|
Hello All,
My requirement is that after I access a machine as \\machinename, I want to see if Printers and Fax folder is listed or not.
Please point me to any sample code or APIs that can enumerate the objcets in the \\machine window or see if an item exists in the window or not.
I see that there are couple of shell APIs like but I didnt know how to use them for my case.
Thanks in Advance...
|
|
|
|
|
Hello
Actually you won't be seeing any printers on that machine unless they are shared, otherwise it would be hacking. If the printer is already shared on the network, then why not acces it from your machine?
Regards
|
|
|
|
|
Thanks for the reply Nader.
Actualy Couple of printers are shared on the machine and I can safely access them. But my requirement is to find if the Printers and Fax folder is listed or not.
Thats I was thinking of enumerating the objects in the window and see if one of the objects is "Printers and Fax" folder.
Please help.
Thanks
|
|
|
|
|
Hello
Well, now I see. Two approaches:
1- Access "\\Computer" and try to enumerate everything on it. This will depend on how you access it.
2- If you you just want "Printers and Faxes" then in a try to access it by "\\Computer\Printers and Faxes"
Regards
|
|
|
|
|
Hello ...
I access another machine from the run command.
I use Process.Start(@"\\" + sMac); and it opens the window for me. Let me know how do I enumerate the objects now.
Also "\\Comp\Printers And Faxes" didnt work for me. Its says no network provider has accepted the path. Let me know if its the right usage.
I think there must be some WMI scripting as well to enumerate the list.
Any piece of source is fine with me.
Thanks in Advance.
|
|
|
|
|
Hi,
I have an html page (with tags) and i want to remove html tags of this page.
I just want keep some elements on this page and remove another.
How can i do that, please ?
Thanks for ur answer.
PS: My page is in WebResult (string type)
A piece of my code:
<br />
string WebResult = string.Empty;<br />
try<br />
{<br />
System.IO.StreamReader MonReader = new System.IO.StreamReader(WebClient.OpenRead(UrlFichier), System.Text.Encoding.ASCII);<br />
WebResult = MonReader.ReadToEnd();<br />
}
|
|
|
|
|
Hi,
Do you know which tags you dont want? If yes then create an XmlDocument from the data in WebResult and search for the tags you want to remove, and remove them !
You can also use XmlNavigator for this purpose.
XmlDocument doc = new XmlDocument(WebResult);<br />
XmlNode xn;<br />
XmlNode tempNode;<br />
string returnVal ="";<br />
try<br />
{<br />
<br />
xn = doc.DocumentElement;<br />
<br />
foreach (tempNode in xn.ChildNodes)<br />
{<br />
if(tempNode.Name == "html tag name")<br />
{ <br />
xn.RemoveChild(tempNode);<br />
}<br />
}<br />
returnVal = doc.InnerText;<br />
}<br />
catch(Exception ex)<br />
{<br />
MessageBox.Show(ex.Message);<br />
}
Also there are various methods for node removal in the XmlDocument class. Please go through them!
<marquee>"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
Anant Y. Kulkarni
|
|
|
|
|
You could use regular expressions in order to match the tags you want removed, and then simply replace them with string.Empty.
For instance, if you want to find a tag, you could use the <img [^>]*?> regular expression:
Regex r;<br />
Match m;<br />
<br />
r = new Regex(@"<img [^>]*?>",<br />
RegexOptions.Singleline | RegexOptions.IgnoreCase);<br />
<br />
for (m = r.Match(WebResult); m.Success; m = m.NextMatch())<br />
{<br />
WebResult = WebResult.Replace(m.Groups[0].ToString(), "");<br />
}
You can also group matches into groups, so for instance if you have a <a ...> linked text </a> , you could use <a [^>]*?>(?<1>.*?)</a> regular expression, that will replace the whole match of the regular expression with the group 1 text (that is the linked Text in the exemple), like:
r = new Regex(@"<a [^>]*?>(?<1>.*?)</a>",<br />
RegexOptions.Singleline | RegexOptions.IgnoreCase);<br />
<br />
for (m = r.Match(WebResult); m.Success; m = m.NextMatch())<br />
{<br />
WebResult = WebResult.Replace(m.Groups[0].ToString(), m.Groups[1].ToString());<br />
}
You can use RegexBuddy[^] to construct oyur regular expressions. It has a 30 perdiod evaluation and it's really easy to use it, because it explains every element and what it does. You can also test your regex. I also recommend a Regular Expressions Tutorial[^]. You fill find regular expressions to be really usefull in other situations as well, and they are also faster than any string parsing code you will write.
regards,
Mircea
Many people spend their life going to sleep when they’re not sleepy and waking up while they still are.
|
|
|
|
|
hi all
my problem is when i try to open an excel workbook, it gives a runtime ComException in win2K where in XP its working fine
Code is
Excel.Workbook wb =wbs.Open("mtc.xls",false, Type.Missing, Type.Missing, Type.Missing, false, Type.Missing, Type.Missing,true, Type.Missing, Type.Missing, Type.Missing,Type.Missing);
Can anyone suggest an idea??
Thanks in Advance
Akhil
|
|
|
|
|
Are you talking about Office 2000/Office XP? (the Office you are trying to automate)
Or Windows 2000/Windows XP? (the OS on which you run your program, also which versions of Office are installed on each of them?)
regards,
Mircea
Many people spend their life going to sleep when they’re not sleepy and waking up while they still are.
|
|
|
|
|
Hi
There are some mp3 files with their text, i want to set it ,when a sentence
of mp3 is heard , in parallel i can set exactly that sentence show as a text.
How could i sync these together?
|
|
|
|
|
Your program should be able to get the playtime and depending on it you show the apropriate text. For instance if your playtime for your mp3 is at 1'30" you should show the text that coresponds to the the one spoken at that particular time.
It's an approach that subtitles for movies use.
regards,
Mircea
Many people spend their life going to sleep when they’re not sleepy and waking up while they still are.
|
|
|
|
|
thanks , but i dont think it could be possible , because i have many mp3 files and many text for them , so it waste many times.
C# couldnt receive any argument from Mp3 files?(like flash object that could send argument to C#)
|
|
|
|
|
There is nothing in the MP3 file that says "place your text here", so there is nothing to get from the MP3 file. You'll have to put the text together yourself and figure out the timing by hand. The MP3 won't have any information to do this automatically.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I have some code that I need to include in my project. The code is organized in a directory structure, such as:
Directory1 - Directory2 - Directory3 - Lots of C# files.
- Directory4 - Lots of other C# files
I right click on the project, and select Add Existing Items, but it would not retain the directory structure, all files are added to the project directory.
If I want to retain the directory structure, the only thing I can do is to manually create a directory structure as the structure of the external code. Go to each directory and import the files in the corresponding directory of the external code.
Its the same for both Visual Studio 2003 and 2005.
Is there a better way to do it ? Or let me rephrase my question, what would be the best way to include a whole external directory structure to your project ?
Thanks for your help.
|
|
|
|
|
In VS2005 there is a sample macro called "GenerateSlnFolderOnDirStructure" that should help you. Open the macro-explorer (Alt+F8 or in mainmenu Extras--Macros--MacroExplorer) and run the macro by double-click.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
You can also copy / move them to the solution's folder and then click "Show All Files" and then select the root folders and "Include in Project". Voila
As of how to accomplish this I wouldn't have a clue at the moment and I'm too lazy to google it
|
|
|
|
|
Hi All,
I have a SQL Server at my office. I can VPN into the office from home in order to access the server. I have a program that makes a connection to this server when it loads up. I do this in a thread, but for the sake of this message I actually put this code in the _Load portion of my app (just to take the delegates, etc, out of the equation). I have a worker thread that checks the connection as well and updates a label to tell you if you are connected or not. If the worker thread detects it is not connected, it will try to re-connect. If I VPN into the office, and then run the app, it works fine. If I disconnect (after I've run the program and connected for the first time) the app does what it should and tells me that I'm disconnected. If I then VPN back in, after a few seconds the label is updated and it says the connection is restored.
The problem that I am facing is that if I am not VPN'd into my office (ie, it cannot see the server from the beginning) it will NEVER connect. It just keeps erroring out in the catch block and the message is that the connection could not be established. I have tried switching the Data Source over to an IP address just to be sure that it was not the DNS resolving that was messing up, and that does not work either. I have tried putting a Thread.Sleep(5000) in the Catch block upon failure just in case I was bombarding the server with too much, that does not work either. I cannot figure out what the problem is. I've done a bunch of different tries at it (ie, redo the connection string each try on the while loop and call Dispose()) ... nothing works. If anyone knows what my problem is I would appreciate a helping hand.
Here's what the code looks like in a nutshell.
while (!bConnectedToServer)
{
myConnectionString = "Initial Catalog=PROGARCHIVE;Data Source=192.1.1.20;User ID=test;Password=test;Connection Timeout=5;";
myConnection = new SqlConnection(myConnectionString);
try
{
myConnection.Open();
bConnectedToServer = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
myConnection.Dispose();
Thread.Sleep(5000); //I've tried it with various values and none at all
}
}
I have also tried something of the nature:
myConnectionString = "Initial Catalog=PROGARCHIVE;Data Source=192.1.1.20;User ID=test;Password=test;Connection Timeout=5;";
myConnection = new SqlConnection(myConnectionString);
while (!bConnectedToServer)
{
try
{
myConnection.Open();
bConnectedToServer = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
Thread.Sleep(5000); //I've tried it with various values and none at all
}
}
|
|
|
|
|
hi,
I also had a similar problem some days ago. I was not able to connect to my network database through Sqlclient. I just changed the SqlClient and put there Oledb. All is working fine now. If you can do it, just give it a try.
Hope it works in ur case also.
I think there is some problem in SqlClient, when it comes to access the database over a LAN. MS should look into it (my perception ofcourse !)
PS:
Caution !!!! You will have to change the SqlConnection, SqlCommand and all other object to OledbConnection and all ..... Also rebuild the connection string using the Oledb Provider.
<marquee>"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
Anant Y. Kulkarni
|
|
|
|
|
Anant Y. Kulkarni wrote: I think there is some problem in SqlClient, when it comes to access the database over a LAN. MS should look into it
Perhaps there was a problem with your network. I've never had a problem connecting over a LAN or through VPN connections.
|
|
|
|
|
Out of curiosity, what happens when you remove the Connection Timeout=5 from the connection string. The default, if not specified, is 15 second to allow the connection to be established, but you are telling it to give up after only 5.
|
|
|
|
|
I never even thought to play with that value at all...
Anyhow, I removed that line and it works now!
The only thing that I am curious about is that when this scenario happens (I am not VPN'd in, I run the program, it cannot connect right away and then I VPN in) ... It will take it about 60-120 seconds to finally make that connection. I put a MessageBox.Show() in the Catch block of the attempt to connect, and it will pop up 5 to 10 times saying "Could not connect...blah blah". But I've run it 30 or 40 times now and it always connects it just takes a lot of failures before it finally does.
Thanks a ton for the input!
|
|
|
|
|
Hi i have a custom control and everything is working fine, except in my test project when i compile it the settings of the control revert back to the default settings, why are my settings not persisting, and how do i go about fixing this problem?
Thank you,
|
|
|
|
|
Hello Tyrus,
Are you talking about property settings during design time?
If yes, it's possible if you are using the "DefaultValue" attribute at your custom properties.
Don't forget to init your class variables correct.
All the best,
Martin
|
|
|
|
|
well all my variables are initialized correctly to start with and then ill go in and change settings and stuff compile and then they dissapear and revert back to the original settings, and it doesn't happen every time i compile either it seems to be somewhat sporadic. i also am getting some wierd tasks telling me that there is object reference not set to an object or somehting like that.
|
|
|
|