![]() |
| |||||||
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 |
| Registered User Join Date: Sep 2009
Posts: 19
| here it is Code: void DownloadFileFromURL(string URL, string SaveFileName)
{
Uri u = new Uri(URL);
Stream s = ((HttpWebRequest)HttpWebRequest.Create(u)).GetResponse().GetResponseStream();
FileStream f = File.Create(SaveFileName);
byte[] r = new byte[4096];
while (true)
{
int num = s.Read(r, 0, 4096);
if (num < 1)
break;
f.Write(r, 0, num);
}
}
Uri u = new Uri(URL); please help me get this to work |
| jamietrent is offline | |
| | #2 |
| Registered User Join Date: Jun 2008
Posts: 1,134
| What is the error message? |
| C_ntua is offline | |
| | #3 |
| Registered User Join Date: Sep 2009
Posts: 19
| umm hold on a sec |
| jamietrent is offline | |
| | #4 |
| Registered User Join Date: Sep 2009
Posts: 19
| invalid URI |
| jamietrent is offline | |
| | #5 |
| Registered User Join Date: Mar 2009 Location: england
Posts: 76
| Code: void DownloadFileFromURL(String URL, String SaveFileName)
{
WebRequest request = WebRequest.Create(URL.StartsWith("http://") ? URL : ("http://" + URL));
WebResponse response = request.GetResponse();
Stream stream = response.GetResponseStream();
FileStream file = new FileStream(SaveFileName, FileMode.Create, FileAccess.Write);
while (true)
{
byte[] buffer = new byte[4096];
int size = stream.Read(buffer, 0, 4096);
if (size > 0)
file.Write(buffer, 0, size);
else
break;
}
file.Close();
stream.Close();
response.Close();
}
|
| theoobe is offline | |
| | #6 |
| Registered User Join Date: Sep 2009
Posts: 19
| it still does it |
| jamietrent is offline | |
| | #7 |
| Registered User Join Date: Mar 2009 Location: england
Posts: 76
| What URL are you using? It worked when I tested it with www.google.com Last edited by theoobe; 09-12-2009 at 11:32 AM. |
| theoobe is offline | |
| | #8 |
| Registered User Join Date: Sep 2009
Posts: 19
| its for my server here is the adress 68.214.84.27/string.wz |
| jamietrent is offline | |
| | #9 |
| Registered User Join Date: Sep 2009
Posts: 19
| here is the code in the button that downloads it i need it to work with this progressBar1.Value += 10 DownloadFileFromURL("68.214.84.27/string.wz", "C:\\program files\\globalc\\cryptonyte"); |
| jamietrent is offline | |
| | #10 |
| Registered User Join Date: Mar 2009 Location: england
Posts: 76
| The code I posted earlier, plus... Code: DownloadFileFromURL("http://68.214.84.27/string.wz", "string.wz");
|
| theoobe is offline | |
| | #11 |
| Registered User Join Date: Sep 2009
Posts: 19
| ummm let me try again |
| jamietrent is offline | |
| | #12 |
| Registered User Join Date: Sep 2009
Posts: 19
| it comes up with an error that says access to the path has been denided well the path is true but it still says that |
| jamietrent is offline | |
| | #13 |
| Registered User Join Date: Mar 2009 Location: england
Posts: 76
| You can only write/modify files in the program files folder, if you have UAC (User Account Control) disabled. I dare say that is why you are denied access. One area of your hard disk which will still have write/modify access is the Application Data folder. You can locate the path to this folder using Code: Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) |
| theoobe is offline | |
| | #14 |
| Registered User Join Date: Sep 2009
Posts: 19
| please tell me how to get it to work |
| jamietrent is offline | |
| | #15 |
| Registered User Join Date: Jun 2008
Posts: 1,134
| theoobe is saying that you cannot save the file at Code: C:\\program files\\globalc\\cryptonyte The Code: Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) So write in your Application Data folder and not in Program Files. Don't know how you can change permissions and be able to write in Program Files |
| C_ntua is offline | |
![]() |
| Tags |
| [code] |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Consuming same Web Service multiple times | cfriend | C# Programming | 2 | 01-10-2006 09:59 AM |
| writing text over a deleted button | algi | Windows Programming | 4 | 05-02-2005 11:32 AM |
| BN_CLICKED, change button style | bennyandthejets | Windows Programming | 9 | 09-11-2002 03:59 AM |