How to download sharepoint files programatically
Hi,In my application i wanted to download the sharepoint file programatically in a webpart.
for that i have used below code.It is getting downloaded but no save dialog box is coming , page is refreshing and file is getting downloaded, no intimations.
/////////
HttpWebRequest request;
HttpWebResponse response = null;
string pathUser = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
string pathDownload = Path.Combine(pathUser, "Downloads");
request = (HttpWebRequest)WebRequest.Create(strURL);
request.Credentials = System.Net.CredentialCache.DefaultCredentials;
request.Timeout = 20000;
request.AllowWriteStreamBuffering = true;
response = (HttpWebResponse)request.GetResponse();
Stream s = response.GetResponseStream();
if (!Directory.Exists("C:\\Users\\Administrator\\Downloads"))
{
Directory.CreateDirectory(@"C:\Users\Administrator\Downloads");
}
string aFilePath = "C:\\Users\\Administrator\\Downloads" + "\\" + strFileName;
FileStream fs = new FileStream(aFilePath, FileMode.Create);
byte[] read = new byte[256];
int count = s.Read(read, 0, read.Length);
while (count > 0)
{
fs.Write(read, 0, count);
count = s.Read(read, 0, read.Length);
}
fs.Close();
s.Close();
response.Close();
///////
So how can we put save dialog box here?
Thanks
Ginnas