Download file from server to local folder
-
Hi All, thanks for the replies, i haven't tried a different path yet. is there anyway i can get this download to work. all i really need to do is allow the user to download the image from the website which is hosted on the server to their local machine, preferably their desktop. living life on the flip side
Agweet wrote:
i haven't tried a different path yet. is there anyway i can get this download to work.
Isn't that a bit like going to the doctor and asking him to cure you but refusing to follow his advice? :confused: /ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
Agweet wrote:
i haven't tried a different path yet. is there anyway i can get this download to work.
Isn't that a bit like going to the doctor and asking him to cure you but refusing to follow his advice? :confused: /ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
it may be OK to ask for advice, then not follow it. However asking again is a bit weird, yes. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
it may be OK to ask for advice, then not follow it. However asking again is a bit weird, yes. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
Luc Pattyn wrote:
it may be OK to ask for advice, then not follow it. However asking again is a bit weird, yes.
You've clearly not handled technical support calls from idiots non-technical users!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
-
Luc Pattyn wrote:
it may be OK to ask for advice, then not follow it. However asking again is a bit weird, yes.
You've clearly not handled technical support calls from idiots non-technical users!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
well, 1. i am not an idiot, and that was not truly called for, but anyways, 2. i did however try a new path after i posted reply, no change, still get the error. is it a permissions issue with the server accessing the local file? or is there something else i am missing? living life on the flip side
-
Luc Pattyn wrote:
it may be OK to ask for advice, then not follow it. However asking again is a bit weird, yes.
You've clearly not handled technical support calls from idiots non-technical users!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
OriginalGriff wrote:
You've clearly not handled technical support calls from non-technical users!
I seem to find ways that ensure they don't come back... :laugh:
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
well, 1. i am not an idiot, and that was not truly called for, but anyways, 2. i did however try a new path after i posted reply, no change, still get the error. is it a permissions issue with the server accessing the local file? or is there something else i am missing? living life on the flip side
Are you able to manually (i.e. thru the Windows UI) create a file with the same path name? That would help identify if it's a permissions issue. /ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
well, 1. i am not an idiot, and that was not truly called for, but anyways, 2. i did however try a new path after i posted reply, no change, still get the error. is it a permissions issue with the server accessing the local file? or is there something else i am missing? living life on the flip side
Just for grins, does this work any better?
WebClient wc = new WebClient();
wc.DownloadFile ("http://.../foo.jpg", @"C:\MyFolder\foo.jpg");You may want to save the image to your user's application data path (to which you have write access). /ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
OriginalGriff wrote:
You've clearly not handled technical support calls from non-technical users!
I seem to find ways that ensure they don't come back... :laugh:
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
Please oh great one! Tell me your secrets! :laugh: [edit]"oh", you clumsy typist Griff, "oh" - not "of"[/edit]
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
-
well, 1. i am not an idiot, and that was not truly called for, but anyways, 2. i did however try a new path after i posted reply, no change, still get the error. is it a permissions issue with the server accessing the local file? or is there something else i am missing? living life on the flip side
Agweet wrote:
i am not an idiot, and that was not truly called for
I'm sorry - did I call you an idiot? If you look at the threads, I was talking to Luc, and making a generic comment about technical support phone calls. Trust me, if I wanted to insult you, you would know all about it! :laugh:
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
-
Just for grins, does this work any better?
WebClient wc = new WebClient();
wc.DownloadFile ("http://.../foo.jpg", @"C:\MyFolder\foo.jpg");You may want to save the image to your user's application data path (to which you have write access). /ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
Hi All, i am trying to download a file from my website on my server, but i keep getting a error: Access to the path 'c:\ImageName.gif' is denied. this is my code i am using:
using (WebClient wcDownload = new WebClient()) { try { webRequest = (HttpWebRequest)WebRequest.Create("http://www.XXXXXXXXXXX.XX.XX/Images/" + strImgName); webRequest.Credentials = CredentialCache.DefaultCredentials; webResponse = (HttpWebResponse)webRequest.GetResponse(); Int64 fileSize = webResponse.ContentLength; strResponse = wcDownload.OpenRead("http://www.XXXXXXXXXXX.XX.XX/Images/" + strImgName); string strFolder = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); strLocal = new FileStream(strFolder + "\\" + strImgName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite); int bytesSize = 0; byte[] downBuffer = new byte[2048]; while ((bytesSize = strResponse.Read(downBuffer, 0, downBuffer.Length)) > 0) { strLocal.Write(downBuffer, 0, bytesSize); } string strAlert = "alert('" + strImgName + " downloaded to " + strFolder + "');"; ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", strAlert, true); } finally { strResponse.Close(); strLocal.Close(); } }
Any help is much appreciated. living life on the flip sideSorry, I have no solution for you. Just a question: Why don't you use WebClient.DownloadFile for downloading the image? Anyway, your code seems to be correct... P.S. Have you heard about Path.Combine (because
+"\\"
doesn't look so good)
-
Hi Ravi, thanks for the reply, i tried downloading the file to the users application data but still get the error.
living life on the flip side
Is is possible that the target file has already been opened (for exclusive read or write), thereby preventing it from being overwritten? Although I think if that were the case you'd see a different exception. /ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com