我试图访问并从远程服务器下载文件李明博和不断收到错误“不支持给定路径的格式。”我使用下面的代码:
string uncPath = Server.MapPath(Path.Combine(@"\\TSTSVR\Users\temp_databaseBackups_000kfkf000",
string.Format("{0}-{1}.bak", ddlDatabases.SelectedValue, DateTime.Now.ToString("yyyy-MM-dd"))));
//download
WebClient webClient = new WebClient();
webClient.DownloadFile(uncPath, ddlDatabases.SelectedValue + "-" + DateTime.Now.ToString("MM-dd-yyyy:hh:mm"));
我正在错误的DownloadFile线。难道我宣布的UNC路径错了吗?该文件夹是存在服务器上,我设置访问具有写权限的所有人。
随着从你我的全部解决了下面的代码问题的正确方向上的一些提示的帮助:
string uncPath = Path.Combine(@"\\TSTSVR\Users\temp_databaseBackups_000kfkf000",
string.Format("{0}-{1}.bak", ddlDatabases.SelectedValue, DateTime.Now.ToString("yyyy-MM-dd")));
//download
Response.ContentType = "bak";
Response.AddHeader("Content-Disposition", "attachment;filename=\"" + ddlDatabases.SelectedValue + "-" + DateTime.Now.ToString("MM-dd-yyyy:hh:mm") + "\"");
Response.TransmitFile(uncPath);
Response.End();
该程序现在将下载的文件从远程服务器需要。
如果远程计算机的Windows控制下工作,那么冒号是不是在允许的路径。