[英]Download a PDF file from the server to client
我要做的是從服務器查找共享文件夾,並在目錄中找到一個文件並將其下載到我的客戶端桌面。
從服務器下載到我的虛擬機桌面可以正常工作,但是,它不能下載到我的客戶端桌面。 它只是拋出一條錯誤消息,指出目標路徑訪問被拒絕。 不知道為什么,因為當我從作為本地運行的虛擬機嘗試它時,它工作得很好。 但是,如果我部署到我們的開發服務器,那么它會拋出該錯誤消息並且不會下載到我的客戶端桌面。
我研究發現由於安全問題,它永遠不會下載到客戶端桌面,但是有沒有辦法從服務器下載到客戶端桌面?
#1。 找出我想要的文件后,從服務器獲取
if (!File.Exists(thisFile))
{
string serverSourcePath = Path.Combine(finalResourcePath + thisFile + ".pdf");
//What I'm trying to do here is that since the client desktop path starts with C:\\Users\MyCredentials\Desktop\... just get the credentials from the user
string userName = User.Identity.Name.Replace("CompanyName\\", "");
string destinationFilePath = Path.Combine(@"C:\Users\" + userName + @"\Desktop\" +
thisFile + ".pdf");
using (var client = new WebClient() { UseDefaultCredentials = true })
{
try
{
client.DownloadFile(serverSourcePath, destinationFilePath);
}
catch (Exception ex)
{
return BadRequest(ex.InnerException.Message);
}
}
}
下載之前,能不能先把文件拉到應用目錄下的一個文件夾下,然后下載到桌面?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.