G
Guest
Why does WebClient.DownloadFile loose my completed path?
Ok, I have a function in my app then when my button is clicked it checks to
see if the files come from a local drive or a http address. The portion of
the code that pulls from the drive works great, but when the http address is
active it changes the originating path to my C:\Windows\System32 folder
instead of the proper path.
I keep the path as a field on my form so I am certain it is correct.
This is my onclick function!
string fileName = BoxImageName.Text;
string filePath = BoxImagePath.Text;
if(Configuration.imageDirType == "Drive")
{
FileInfo MyFileInfo;
long StartPos = 0, FileSize;
MyFileInfo = new FileInfo(filePath);
FileSize = MyFileInfo.Length;
Response.ContentType = "application/x-msdownload";
Response.AppendHeader( "content-disposition","attachment; filename=" +
fileName);
Response.WriteFile(filePath, StartPos, FileSize);
Response.End();
}
else if(Configuration.imageDirType == "WWW")
{
WebClient myWebClient = new WebClient();
myWebClient.DownloadFile(filePath,fileName);
}
The BoxImagePath.Text does have the right information in it, when you copy
it's contents to a browser window it displays perfectly, so the path is
correct.
What else could I be missing??
Is there a better way I should be doing this??
Is there a way to force this download to prompt for a saveas location like
the x-msdownload does??
Thanks all!
Ok, I have a function in my app then when my button is clicked it checks to
see if the files come from a local drive or a http address. The portion of
the code that pulls from the drive works great, but when the http address is
active it changes the originating path to my C:\Windows\System32 folder
instead of the proper path.
I keep the path as a field on my form so I am certain it is correct.
This is my onclick function!
string fileName = BoxImageName.Text;
string filePath = BoxImagePath.Text;
if(Configuration.imageDirType == "Drive")
{
FileInfo MyFileInfo;
long StartPos = 0, FileSize;
MyFileInfo = new FileInfo(filePath);
FileSize = MyFileInfo.Length;
Response.ContentType = "application/x-msdownload";
Response.AppendHeader( "content-disposition","attachment; filename=" +
fileName);
Response.WriteFile(filePath, StartPos, FileSize);
Response.End();
}
else if(Configuration.imageDirType == "WWW")
{
WebClient myWebClient = new WebClient();
myWebClient.DownloadFile(filePath,fileName);
}
The BoxImagePath.Text does have the right information in it, when you copy
it's contents to a browser window it displays perfectly, so the path is
correct.
What else could I be missing??
Is there a better way I should be doing this??
Is there a way to force this download to prompt for a saveas location like
the x-msdownload does??
Thanks all!