简体   繁体   中英

c# The given path's format is not supported. UNC Path

I am trying to access and download a bak file from a remote server and keep getting the error "The given path's format is not supported." The code I am using below:

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"));

I am getting the error at the DownloadFile line. Am I declaring the UNC path wrong? The folder is there on the server and I set access to Everyone with write permissions.

With the help of a few hints in the right direction from you all I solved the problem with the following code:

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

The program will now download the file need from the remote server.

如果远程计算机在Windows控制下工作,则path中不允许冒号。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM