解決網絡 下載 句柄無效。 (異常來自 HRESULT:0x80070006 (E_HANDLE))


首先要共享該文件

其次 在安全里加IISSHARED 是IIS賬號

 

下載代碼

  #region 下載
        /// <summary>
        /// 下載
        /// </summary>
        /// <param name="strPath"></param>
        /// <returns></returns>
        [LoginFilter]
        public ActionResult FilePathDownload(string strPath)
        {
            int index = strPath.LastIndexOf(@"\");
            string fileName = "";
            if (index > 0)  
            {
                fileName = strPath.Substring(index + 1, strPath.Length - index - 1);
            }
            int fileIndex=strPath.IndexOf(@"\OrderFiles\");
            var path = Server.MapPath("~/OrderFiles/" + strPath.Substring(fileIndex).Replace("\\", "//"));
            return File(path, "application/x-zip-compressed", fileName);
            
        }
        #endregion

 

頁面

 <tr>
      <th>訂單附件:</th>
      <td>
                        @if (Model.OrderFilesList.ToList().Count > 0)
                        {
                            var filePath = @Model.OrderFilesList.ToList().FirstOrDefault();
                            <a href="@filePath.FilePath" style="display:none">下載附件</a>
                          
                            using (Ajax.BeginForm("FilePathDownload", "ForeignTradeOrder", new { strPath = @filePath.FilePath }, new AjaxOptions
                            {
                                HttpMethod = "Post"
                            }, new { id = "myForm" }))
                            {
                               <a href="#" id="adown" onclick="downLoadClick()">下載附件</a>
                               <input type="submit" id="btnDownLoad" style="display:none" value="下載附件"/>
                            }
                        }
                        else
                        {
                             <span>無</span>
                        }
                        </td>
     </tr>     

//下載
 function downLoadClick() {
    document.getElementById('myForm').submit();
}

IIS配置站點如下 站點下的虛擬目錄盤符的路徑如下


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM