|
string url="https://......./file.exe"
.............
try
{
WebClient myWebClient = new WebClient();
myWebClient.Credentials=CredentialCache.DefaultCredentials;
myWebClient.DownloadFile(url,path);
}
But server returns an error:(403) Forbidden
I think that I must to give a sertificate. But how can I do it in WebClient?
Thank you for answer.
|
|
|
|
|
|
You can also check out http://www.codeproject.com/useritems/filedownloader.asp[^].
You almost have things setup correctly, but the CredentailCache.DefaultCredentials will supply the request object with the default system credentials, not the username and password required by the web site.
In order to do that, you will need to do something like this:
Uri uri = new Uri(url);
CredentialCache credCache = new CredentialCache();
NetworkCredential userCred = new NetworkCredential(username, password, domain);
credCache.Add(uri, "Basic", userCred); The "NTLM" in the call is a string that specifies the authentication type. The valid choices are "NTLM", "Digest", and "Basic". You will need to use the type that is appropriate for your specific case.
Also, make sure that you don't need a proxy to be specified.
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
Hi,
I need to run some part of my code in a different security context. For eg. when i try to write to a remote share it throws access denied exception. but i have the username\pwd of that machine. Please help
James Poulose
|
|
|
|
|
Hi,
i am not able to fire xpath queries (SelectSingleNode method with namespace object) to a SOAP xml. It complains about a namespace problem. here is a sample
<soap:envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:body>
<setresponse xmlns="http://tempuri.org/">
<smessageid>EEF0AFFE-A9F5-41A2-AE82-4601E3E2465F
i want the data in the "sMessageID" element. Any idea??
James Poulose
|
|
|
|
|
Your XML snippet isn't visible. Please modify your post by either replacing all < with &lt; or check the "Ignore HTML tags in this message" option beneath the smilie selection. Furthermore it will be helpful to see XPath expression your currently using.
"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 Cookwww.troschuetz.de
|
|
|
|
|
So sorry for the inconvinience caused. Please find the xml below
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<SetResponse xmlns="http://tempuri.org/">
<sMessageID>EEF0AFFE-A9F5-41A2-AE82-4601E3E2465F</sMessageID>
</SetResponse>
</soap:Body>
</soap:Envelope>
xpath i am trying to use the "sMessageID" element
/soap:Envelope/soap:Body/SetResponse/sMessageID
Regards,
James
|
|
|
|
|
I'm not sure, but I think the problem is that the SetResponse and sMessageID element are in the "http://tempuri.org/" namespace (defined as standard namespace without prefix) but this doesn't reflect in your XPath expression.
Try to use the SelectSingleNode overload that additionally takes a XmlNamespaceManager instance. Add entries for the pair (soap "http://schemas.xmlsoap.org/soap/envelope/") and (somePrefix "http://tempuri.org/") and use the somePrefix in your XPath: /soap:Envelope/soap:Body/somePrefix:SetResponse/somePrefix:sMessageID .
"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
|
|
|
|
|
Hi,
I have already done all the namespace mechanisms known to me.The problem is , if i add a namespace on my own, it should be applicable to all parts in the xpaths, not just the last couple of parts. I think, we need to find a way to specify that "soap" prefix is not a namespace and it is just an element name. Any way thanks for your reply
Regards,
James
|
|
|
|
|
I'm a current MCAD student. Hope someone can help me with a small query. I am working on an application that saves student records to an xml file. Through using an Xml Schema, a dataset generated from the xml schema, a new student row and the WriteXml method, I can save a new record to an xml file.
However, if I display an existing record to a series of textboxes and want to amend the record, how do I save the amended record back to the xml file. If I find a student row using the Student ID, populate the textboxes with the details, then use WriteXml method again, that saves a new record to the file instead of amending the existing records. I therefore conclude this is the wrong way of doing things so I am asking if anyone can point me in the right direction.
Is there another dataset method I should be using that I am not aware of to update an existing record. The NewStudentRow() method adds a new record, is there another method for updating?
Grateful for any help.
|
|
|
|
|
İs there any method taht convert all items in a string array to an int array
String[] --> int[] ???
karanba
|
|
|
|
|
try to convert string array items to integer and add it to int array one by one
int[0]=int.Parse(String[0]);
.
.
.
.
rahul
|
|
|
|
|
Check out the Array.ConvertAll<> method.
---
b { font-weight: normal; }
|
|
|
|
|
thank array.convert.all work fine for me
karanba
|
|
|
|
|
Hi,
When a network cable is plugged or unplugged from Lan card windows displays a message "LAN is now connected" or "Network cable is unplugged" in system tray. My question is how can i build an application which display such messages when a cable is unplugged from network card.
Thanx in advance.
Regards
Aamer
|
|
|
|
|
|
Hi,
I want to create a process using a user's login info. In managed C++ there is a "CreateProcessWithLogonW" function but I want to accomplish my task with managed code.
Is there any equavalent method for "CreateProcessWithLogonW"? How can I start a process using a logon info?
thanks,
- ferudun
|
|
|
|
|
Use an overload of Process.Start that takes an instance of ProcessStartInfo class which provides properties for logon information.
"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
|
|
|
|
|
Thanks for your reply but it is not clear to me which attributes of ProcessStarInfo has to be supplied with user's login name and password.
Simply, I need running a program with another user's privileges. When I use "runas" DOS command I am prompted to enter the user's password. That's the problem. I don't want to supply the password during runtime. I want the job to be done automatically.
thanks,
|
|
|
|
|
The properties are called UserName and Password . I saw right now that both are new in framework version 2.0 so that's probably the reason why you didn't find them. In case you're using a framework version prior 2.0, there's probably no managed way and you have to p/invoke the unmanaged function mentioned in your first post.
"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
|
|
|
|
|
thanks,
i am using 1.1
|
|
|
|
|
In case you don't already knew it, take a look at http://www.pinvoke.net[^]. It's a great help when you have to work with unmanaged apis.
"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
|
|
|
|
|
Hi all,
I want to check whether computer is connected to the network or not. I use a boolean method IsNetworkConnected() as shown below. I wonder if this method is OK, if not can you suggest any method?
public bool IsNetworkConnected()<br />
{<br />
IPAddress IPAd;<br />
ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());<br />
IPAd = ipHostInfo.AddressList[0];<br />
<br />
if (IPAd.ToString() == "127.0.0.1")<br />
{<br />
return false;<br />
}<br />
else<br />
{<br />
return true;<br />
}<br />
}<br />
|
|
|
|
|
i am sure this method will work.
regards
sAqIb
"Our scientific power has outrun our spiritual power. We have guided missiles and misguided men."
Dr. Martin Luther King Jr.
|
|
|
|
|
It really depends on what you mean by "connected to the network". If you are only interested in determining if the network is available (ie, the cable is plugged in and the NIC is getting a signal) you can use the NetworkAvailabilityChangedEventHandler delegate[^].
Using the AddressList property as you show above isn't the most reliable way to check as it may not return the addresses in the order you are expecting, so AddressList[0] isn't guaranteed to be the loopback address. (The better way to test if it is the loopback address is also to do if (IPAd == IPAddress.Loopback) or if (IPAddress.IsLoopback(IPAd)) .)
If you need to know if you are connected to the internet, the best options are to try to browse to a website or ping a known address.
Using ping:
bool internetAvailable = false;
Ping pinger = new Ping();
PingOptions pingOptions = new PingOptions(1, true);
byte[] pingResults = new byte[2];
PingReply pingReply = pinger.Send("www.microsoft.com", 25000, pingResults, pingOptions);
if (pingReply.Status == IPStatus.Success)
{
internetAvailable = true;
}
Using website:
bool internetAvailable = false;
Uri requestUri = new UriBuilder("http", "www.microsoft.com").Uri;
HttpWebRequest connectivityCheck = WebRequest.Create(requestUri) as HttpWebRequest;
connectivityCheck.Timeout = 25000;
HttpWebResponse connectivityResponse = connectivityCheck.GetResponse() as HttpWebResponse;
if (connectivityResponse.StatusCode == HttpStatusCode.OK)
{
if (!connectivityResponse.IsFromCache)
{
internetAvailable = true;
}
}
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|