Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在ASP.NET web应用程序中调用本地图片库路径_C#_Asp.net_Image_Visual Studio_Webforms - Fatal编程技术网

C# 如何在ASP.NET web应用程序中调用本地图片库路径

C# 如何在ASP.NET web应用程序中调用本地图片库路径,c#,asp.net,image,visual-studio,webforms,C#,Asp.net,Image,Visual Studio,Webforms,所以我在c中有一个ASP.NET web应用程序。我创建了一个下载文件的方法,效果很好。目前,正如我指出的那样,它正在D驱动器中加载文件。但是,我想在本地图片库下载文件。 以下是我的代码: protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Download") { Response.Clear(); Response.

所以我在c中有一个ASP.NET web应用程序。我创建了一个下载文件的方法,效果很好。目前,正如我指出的那样,它正在D驱动器中加载文件。但是,我想在本地图片库下载文件。 以下是我的代码:

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();
  }
}

要获取服务器上“我的图片”库的路径,可以使用以下方法,例如:

var path = Path.Combine( 
    Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), 
    "myfile.jpg");
webClient.DownloadFile(Server.MapPath("~/Images/") + e.CommandArgument, path);

这将使用应用程序池正在使用的帐户的MyPictures文件夹

图片库是Windows文件夹的枚举。默认情况下,它是以下两个:c:\Users\\My Pictures和c:\Users\Public\Public Pictures是否要更改文件下载到用户计算机或服务器上的路径?@Markusserver@Sangman嗨,它不起作用了:如果我输入GetSpecialFolderPath,它是GetSpecialFolderPath还是GetFolderPath,我有错误-环境不存在谢谢!你的密码有效。只是它是GetFolderPath而不是GetSpecialFolderPath@alisafathima很高兴听到它起作用了。抱歉-GetSpecialFolderPath错误。只有枚举名为SpecialFolder。