Reputation: 15
So i have a ASP.NET web app in c#. I've create a method to download files and it works fine. Currently, it's donwloading files in D drive as i pointed out that path. However, i want the files to be downloaded in Local Pictures Library. Below are my codes:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Download")
{
Response.Clear();
Response.ContentType = "application/octect-stream";
Response.AppendHeader("content-disposition", "filename=" + e.CommandArgument);
Response.TransmitFile(Server.MapPath("~/Images/") + e.CommandArgument);
WebClient webClient = new WebClient();
//How to add path for pictures library in local machine?
webClient.DownloadFile(Server.MapPath("~/Images/") + e.CommandArgument, @"d:\myfile.jpg");
Response.End();
}
}
Upvotes: 0
Views: 52
Reputation: 22511
In order to get the path of the My Pictures library on the server, you can use the Environment.GetFolderPath method, e.g.:
var path = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.MyPictures),
"myfile.jpg");
webClient.DownloadFile(Server.MapPath("~/Images/") + e.CommandArgument, path);
This will use the MyPictures folder of the account that the application pool is using.
Upvotes: 1