المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Access to the path is denied



C# Programming
07-27-2012, 04:30 AM
Hello everyone

This is a program for downloading a file from a url
when i download a file i got a error like access to the path is denined can any one tell me why this happen

This is my code.
public static void Download(String strURLFileandPath, String strFileSaveFileandPath) { HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(strURLFileandPath); HttpWebResponse ws = (HttpWebResponse)wr.GetResponse(); Stream str = ws.GetResponseStream(); byte[] inBuf = new byte[100000]; int bytesToRead = (int)inBuf.Length; int bytesRead = 0; while (bytesToRead > 0) { int n = str.Read(inBuf, bytesRead, bytesToRead); if (n == 0) break; bytesRead += n; bytesToRead -= n; } try { FileStream fstr = new FileStream(strFileSaveFileandPath, FileMode.OpenOrCreate, FileAccess.Write); fstr.Write(inBuf, 0, bytesRead); str.Close(); fstr.Close(); } catch (Exception e) { MessageBox.Show(e.Message); } } private void button2_Click(object sender, EventArgs e) { if (phpurl.Text == "") { MessageBox.Show("Invalid Url"); } else if (Uri.IsWellFormedUriString(phpurl.Text, UriKind.Absolute) == false) { MessageBox.Show("Invalid Url"); } else { Download(phpurl.Text, @"D:\test"); } } Also this is my manifest file
</span span class="code-SummaryComment"version/spanspan class="code-keyword"="/spanspan class="code-keyword"1.0"/span span class="code-SummaryComment"encoding/spanspan class="code-keyword"="/spanspan class="code-keyword"utf-8"/spanspan class="code-SummaryComment"?>

Please help me..
http://www.barakasoft.com/script/Forums/Images/smiley_confused.gif http://www.barakasoft.com/script/Forums/Images/smiley_confused.gif http://www.barakasoft.com/script/Forums/Images/smiley_confused.gif
Thanks in advance.