2016-04-14 57 views
0

我使用the library MPXJ这很好,但我现在希望用户能够上传自己的文件(asp.net-mvc网站),它作为HttpPostedFileBase在服务器端表单发布,然后我转换到内存流使用:C#库MPXJ能够从MemoryStream中读取文件吗?

var stream = new MemoryStream(); 
    httpPostedFile.InputStream.CopyTo(stream); 

鉴于这种情况,我想弄清楚我如何能在它读成一个MemoryStream(相对于磁盘上的文件位置)

现在,我有这样的事情:

public ProjectFile Import(string filePathandName) 
    { 
     MPPReader reader = new MPPReader(); 
     ProjectFile project = reader.read(filePathandName); 

和我想有这样的事情:

public ProjectFile Import(MemoryStream stream) 
    { 
     MPPReader reader = new MPPReader(); 
     ProjectFile project = reader.read(stream); 

这是可能的“原生地”或者我需要将文件保存在我的服务器上,然后从那里阅读(试图避免该选项)?

回答

1

MPPReader.Read()该方法只接受4种类型的参数,其中没有一个是一个MemoryStream和所有,但一个似乎是被库本身内定义的类型:

  • 的java.io.File
  • 的java.io.InputStream
  • org.apache.poi.poifs.filesystem.POIFSFileSystem

您目前正在使用的string参数,因为它需要一个路径,但它似乎是你可能会得到最接近将尝试将现有MemoryStream对象复制到库中找到的InputStream类型并使用它(如果存在这种类型的支持)。

1

MPXJ一般有一对称为DotNetInputStreamDotNetOutputStream类充当包装器净流,使得它们可以在那里MPXJ期待的Java InputStreamOutputStream使用。

这里是DotNetInputStream相关评论:

/// <summary> 
/// Implements a wrapper around a .Net stream allowing it to be used with MPXJ 
/// where a Java InputStream is expected. 
/// This code is based on DotNetInputStream.java from the Saxon project http://www.sf.net/projects/saxon 
/// Note that I've provided this class as a convenience so there are a matching pair of 
/// input/output stream wrapper shopped with MPXJ. IKVM also ships with an input stream wrapper: 
/// ikvm.io.InputStreamWrapper, which you could use instead of this one. 
/// </summary> 

您应该能够使用这个类来实现你在你的问题描述。