|
Never Mind.
I was able to find out how to do it.
DirectoryEntry iis = new DirectoryEntry("IIS://" + Environment.MachineName + "/w3svc");
foreach (DirectoryEntry site in iis.Children)
{
if (site.SchemaClassName == "IIsWebServer")
{
String siteName = site.Name;
foreach (String propertyName in site.Properties.PropertyNames)
{
PropertyValueCollection values = site.Properties[propertyName];
foreach (object val in values)
{
Console.WriteLine(propertyName + ": " + val);
}
}
}
}
This will get the list of web sites on IIS and their properties. I don't know if this will work for IIS 7 right now.
|
|
|
|
|
Hi all!,
I have a weird question and some code that isn't quite right. I am creating a personal project where I have an already-existing text file which consists of mainly symbols and standard text as follows:
Sample Text File contents:
<jason="human, being, boy, male, animal" />
<human="instinctive, funny, destructive" />
http://www.my_soon-to-be_homepage.com.au/
<qualities="smart, intelligent, funny" />
This file may contain X number of lines, and what I am trying to do is search for the in-betweens, what I mean by that is I want to be able to search for the keywords (human, being, person, hairy, funny, intelligent etc..) that are inbetween the symbols and then put those found keywords into a string so that i can cut, copy, paste, change them at my own will. Then I need to be able to search for a URL that is within that same text file. And then put that URL into a string so I can cut, copy, paste etc..... into a textBox.
I have some code here that searches but it doesn't work the way i want it to. I'd appreciate any samps, tutorials, advice/ or ANY help i can get from anybody. Thanks for taking the time to read this. I hope it wasn't too confusing..
best regards,
j.t.
j.t.
|
|
|
|
|
If you make your file XML you can use an XML reader to access the attribute values. (The values in quotes)
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
Either use the System.XML namespace thus formatting your document to use XML standard formatting, either use the System.Text.RegularExpressions namespace similar to:
System.Net.RegularExpressions reg = new System.Net.RegularExpressions.Regex("<[a-z]+=""([a-z,\s]+)"" \/>");
Use expresso to get the expression that best fits ur needs. The above is just a shallow example.
|
|
|
|
|
Oh, sorry, I forgot to post the code I mentioned in my Question. Thanks for helping me, both of you It's much appreciated:
using System.IO;
using System.Text.RegularExpressions;
private void SearchLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
if( File.Exists("C:\\Users\\Jase\\Desktop\\Test.txt"))
{
string FileName = "C:\\Users\\Jase\\Desktop\\Test.txt";
StreamReader SearchText = new StreamReader(FileName);
string ReadAll = SearchText.ReadToEnd();
SearchText.Close();
string regMatch = SearchTextBox.Text;
if (Regex.IsMatch(ReadAll, regMatch))
{
MessageBox.Show("Found\n" + "" + regMatch);
}
else
{
MessageBox.Show("Not found\n");
}
}
else
{
MessageBox.Show("Non-Existant File.");
}
}
The only problem with this code is it requires somebody to enter text into a textbox and then it will search for that text in an existing file. I actually need to just search for anything that is inbetween two quotes ("sample thing").
I tried both of your suggestions and I got a little confused and it didn't work, so I went to MSDN before posting another question here and I left MSDN even more confused. Thanks for your quick replies
j.t.
|
|
|
|
|
IsMatch returns a boolean whether it found or not your regex expression in the input string.
The correct way to use regex would be with this basic regex
Regex reg = New Regex("""(.+?)""", RegexOptions.IgnoreCase | RegexOptions.Multiline);
MatchCollection mtc = reg.Matches("input string");
this will return a MatchCollection which u can loop through to get every match of the pattern in the input string. Use the GetEnumerator method of the above MatchCollection to loop through the matches.
Code? Yeah i love it fried together with a glass of wine.
|
|
|
|
|
My problem: reading bits from a file and manipulate them.
So I have to get the 0's and the 1's from a file in an array or something, adjust them and make a file again with them. Is this possible? You guys could help me with some example code or some useful function names. I would really appreciate that
|
|
|
|
|
load bytes from your file and manipulate them using System.Collection.BitArray, convert again to bytes then save to file.
hope it helps
dhaim
ing ngarso sung tulodho, ing madyo mangun karso, tut wuri handayani. "Ki Hajar Dewantoro"
in the front line gave a lead, in the middle line build goodwill, in the behind give power support
|
|
|
|
|
yes it helps, but
how can I convert BitArray to byte[] ?
BitArray myBitArray = new BitArray(myBytesArray);
byte[] myNewByte = ... ?
|
|
|
|
|
This should work....haven't really tested it.
String path = "path to your file";
System.IO.StreamReader reader = new System.IO.StreamReader(path);
String data = reader.ReadToEnd();
byte[] buffer = Encoding.ASCII.GetBytes(data);
System.Collections.BitArray bits = new System.Collections.BitArray(buffer);
Hope this helps
|
|
|
|
|
yes it helps, but
how can I convert BitArray to byte[] ?
BitArray myBitArray = new BitArray(myBytesArray);
byte[] myNewByte = ... ?
|
|
|
|
|
Check msdn for BitConverter. That should help.
|
|
|
|
|
Hello! I'm new to C# and .NET. Most of the developement I've done lately is in PL/SQL and/or Perl, so C# is "a bit" of a change for me. I've got an architecture question first which I'm sure will lead to more questions.
I work for a company that has hundreds of remote devices around the country. I need to write an app that, in a nutshell, reads the details of these devices from a database, contacts them via a phone call using a modem pool, downloads a data file, then updates certain fields in the database.
I'd like opinions on whether this is a good way to do it or not:
I'm thinking of writing two separate apps that communicate via remoting. One app (the client) would be the one that 'talks' to the database. It periodically reads the database to see which devices need to be contacted. It would be multi-threaded so it can initiate multiple contacts at once.
The second app (the server) would be responsible for controlling the modem pool (up to 20 modems/phone lines). It would take a request from the client, contact the device, and get the data file, then respond back to the client with the status of the call (sucess or failed and why failed).
Does this sound like a good way to proceed? Any hidden 'gotchas' I should know about? Threading, remoting, dialing a modem, etc, is all new to me so this should be..... 'interesting'.
- Dave -
|
|
|
|
|
I'm getting crazy...
I've tried to run through this.Controls
...but it only found the MenuStrip and ToolStrip. The names of the items like "mnuOptions" weren't listed.
So I've tried stupid like this.components.Components.GetEnumerator()
...and got only one element.
All objects can be accessed by typing this. and the name of object. Even those of the MenuStrip or ToolStrip. But at runtime they can't be accessed by this.Controls["menuItemXY"] .
I know about recursive getting controls. But this solution doesn't get the items of a MenuStrip.
Is there any solution to get really all objects in a form at once and without switching the type of object?
modified on Thursday, November 13, 2008 11:16 AM
|
|
|
|
|
All controls have a property called Controls which return subcontrols so you need to write a recursive method that loops on all controls on the form and calls itself for every control it finds at any stage.
|
|
|
|
|
You'll have to walk the hierarchy of Controls as each Control itself has a Controls collection. For menus, groupboxes, and things of that sort that can contain other controls you cannot access the internal controls from the Form's Controls collection directly; rather, through the Controls collection of the container itself.
Keep It Simple Stupid! (KISS)
|
|
|
|
|
I found a good and understood answer to this question: Items of ToolStrip and MenuStrip aren't controls, so that's the reason why it doesn't work to run through the control collection, even if it's recursive.
I have to choose the right handling after getting the type of control and run through the type of what ever is in it. For me it's not an ideal solution, but there isn't a general solution for all types, I guess.
|
|
|
|
|
Hi,
I have developed an application that processes WAV (PCM) files in C#. My issue is that it is possible to get compressed wave files in GSM format as well. What can be the best way to convert them to PCM, programmitcally, so that I can use them with my application. There seems to be a few options like using winmm.dll or audio compression manager. Unfortunately I couldnt find relevant resources for properly using these in C#. Any pointers in the right direction will be much appreciated. Thanks
Kind Regards,
Fahd
|
|
|
|
|
Just done a quick google search,and is seams like SOX[^] is the easiest.
Apparently to do .gsm to wav you just need
sox -V in.gsm -s -w <code>out.wav
where in.gsm is your gsm file and out.wav is the new wav.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Hi
Thanks for your reply Dave, but I want a way to do it within my application. My application is a multithread app that will be handling multiple wav streams coming in so probably can't use the sox exe as well. Is there any other way?
regards
Fahd
|
|
|
|
|
You should be able to use the exe using Process.Start / ShellExecute either passing the commands as arguments, or creating a bat file with the commands in and running that from your app, or creating a wrapper around the relevant dlls (if there are any?).
If none of those work, or don't appeal - the source code is available (in C, not C#) for sox. You can study that and write your own .net implementation.
Either one could prove to make an interesting subject for an article!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
I have 2 threads, one application thread and the workflow foundation thread. My application thread now throws an exception, but the try-catch-block is in a method that is called in the workflow thread. The problem is, this exception is not caught in the try-catch-block. I am wondering if it is possible to somehow marshal the throwing of the exception to the workflow thread. Does anyone know this?
|
|
|
|
|
I have some javascript with activeX object. For setting parameter value of this activex object this code is used:
ObjectCache = new ActiveXObject("Shell.ObjectCache");
ObjectCache("variableName") = "value";
How can I write my assembly that will work with code above?
I know that assembly uses default method if this helps.
|
|
|
|
|
The ShowDialog(IWin32Window) may take a Form object instance as its parameter.But the Form doesn't implement IWin32Window interface.
Anyone can explain it?
Thank you very much!
|
|
|
|
|
Form class inherits from ContainerControl class which inherits ScrollableControl which in turn inherits from Control which ...
I hope you can continue from here and find out answer to your question
|
|
|
|