2012-01-13 33 views
1

我正在使用链接按钮从服务器下载文件。 当我使用页面的完整路径时,它工作正常。下载链接无效

下载链接位于默认页面上。

http://mydomain.com/default.aspx 但不使用http://mydomain.com/

和offcourse它在本地主机workign不是在服务器上时,工作。

我使用的代码是

try 
     { 

      // System.String filename = this.ViewState["ImageName"].ToString(); 
      string fileName = "filename.pdf"; 
      // set the http content type to "APPLICATION/OCTET-STREAM 
      Response.ContentType = "APPLICATION/OCTET-STREAM"; 

      // initialize the http content-disposition header to 
      // indicate a file attachment with the default filename 
      // "myFile.txt" 
      System.String disHeader = "Attachment; Filename=\"" + fileName + 
       "\""; 
      Response.AppendHeader("Content-Disposition", disHeader); 

      // transfer the file byte-by-byte to the response object 

      System.IO.FileInfo fileToDownload = new 
       System.IO.FileInfo(Server.MapPath("~/UserUploads/") + fileName); 
      Response.Flush(); 
      Response.WriteFile(fileToDownload.FullName); 
     } 
     catch (System.Exception ex) 
     // file IO errors 
     { 
      //SupportClass.WriteStackTrace(ex, Console.Error); 
      throw ex; 
     } 
} 

请帮我提前来解决这个

感谢

世斌

+2

您能否定义'not working'这个概念?你有错误吗?怎么了? – 2012-01-13 08:10:33

+0

_Works在我的机器上:) – 2012-01-13 08:15:06

+0

没有错误即将到来。页面jst后支持..多数民众赞成在所有 – 2012-01-13 08:35:56

回答