First, I want to make sure you know that cache is only temporary (You
shouldn't rely on it, right code to check for it, it is simply to speed
things up). Second, it looks to me like you are writing code more
complicated than necessary. Here is a much simpler way to have a client
download a file, and here is the website where I learned how to do it:
Private Sub btnDownload_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnDownload.Click
Response.ClearContent()
Response.ContentType = "text/plain"
Response.AddHeader("content-disposition",
"attachment;filename=download.txt")
'Response.WriteFile(Server.MapPath("download.txt") )
Response.Write("This is a test download text file" & ControlChars.NewLine)
Response.Write(Date.Now.ToLongDateString() & " " &
Date.Now.ToLongTimeString())
Response.End()
End Sub
My example lets the client download a text file that contains the following
text:
This is a test download text file
<date> <time>
If you want to have the client download another file type, replace
"text/plain" with the MIME type of your file and use the WriteFile method
instead of the Write method.
http://www.dotnetspider.com/technology/kbpages/553.aspx
Good Luck!
--
Nathan Sokalski
nj********@hotmail.com http://www.nathansokalski.com/
<ci**********@emersonProcess.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
I am using DownloadFile() on a C# web app to download a file to a
client. When I set the WebClient credentials to the DefaultCredentials,
I get a 401 Unauthorized exception.
WebClient myWC = new WebClient();
myWC.Credentials = CredentialCache.DefaultCredentials;
myWC.DownloadFile(myRemoteUri, myFile);
However, when I set the credentials using a username and password it
works.
myWC.Credentials = new Net.NetworkCredential("username","pwd");
Can someone please explain to me why I cannot use the default
credentials as I do when I'm calling a web service.
MyWS proxy = new MyWS();
proxy.Credentials = CredentialCache.DefaultCredentials;
proxy.CallAMethod();
// this works!
I would expect the DefaultCredentials to work for the WebClient as well
since I have the credentials in cache (from the user login to get to
the page). The web site is configured for Integrated Windows
authentication. The form pages use basic authentication, and the web
services use Integrated Windows (so we can pass the credentials).
Thanks,
Cindy