[英]Directory Not Found Exception…yet I can browse to the directory?
在我的 asp.net 頁面中,我正在將文件從本地驅動器復制到服務器。
'append the name to the id number and generate the file name
strFileName = System.Configuration.ConfigurationManager.AppSettings("strAttachmentsPath") & l.ToString & "_" & CType(Session("FileName"), String)
'upload the file
'FileUpload1.SaveAs(strFileName)
System.IO.File.Copy(CType(Session("Attachment"), String), strFileName, True)
strFileName
包含一個服務器路徑,如"\\myServer\images\theNewFileName.jpg"
Session("Attachment")
包含我的本地路徑'C:\Users\myUser\Desktop\AccountsFrance.txt'
但是當我運行此代碼時 asp.net 會引發異常:
但我可以輕松瀏覽到這個文件....我不明白為什么會這樣:(
假設為網絡服務設置了寫入目標目錄的權限,請執行
strFileName = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings("strAttachmentsPath") & l.ToString & "_" & CType(Session("FileName"), String))
到目錄,看看你是否仍然遇到權限問題。
另外,Session("Attachment") 的值是多少? 那需要是服務器上的文件路徑,而不是用戶端。 通常,在上傳場景中,您從上傳控件中獲取 byte[] 並將其寫入服務器上的 stream。 然后,您可以采用該文件路徑並將其復制到其他地方。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.