使用Response.TransmitFile抛出PathTooLongException

时间:2015-05-09 20:03:32

标签: c# asp.net

我需要将文件传输到客户端而不缓冲到内存中 所以我使用了Response.TransmitFile但是这个函数抛出了PathTooLongException 我可以在IO.File函数中处理这个异常,但是我没有找到任何这个TransmitFile的解决方案,堆栈跟踪就像吹了

Message :The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

StackTrace :   at System.IO.PathHelper.GetFullPathName()
   at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at System.Web.HttpResponse.TransmitFile(String filename, Int64 offset, Int64 length)
   at _Default.Page_Load(Object sender, EventArgs e) in Download.aspx.cs:line 151
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

1 个答案:

答案 0 :(得分:0)

你真的需要阅读错误:

  

消息:指定的路径,文件名或两者都太长。该   完全限定的文件名必须少于260个字符,并且   目录名称必须少于248个字符。

问题非常清楚。我想你的路径或文件名太长了。

检查您传输的文件名:

---
title: "Untitled"
output: 
  html_document:
    highlight: espresso
---

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r}
summary(cars)
```

etc...
相关问题