Wcf 如何从没有';t源于文件系统。(sharepoint内容数据库)
我试图在WCF3.5中使用REST样式的URL而不是SOAP返回流。其想法是从SharePoint 2010中读取一个文件,然后将其传递回客户端。(我们有理由这样做而不是使用SharePoint services,但我离题了。)似乎发送文件的唯一方法是使用一个Wcf 如何从没有';t源于文件系统。(sharepoint内容数据库),wcf,sharepoint,filestream,memorystream,Wcf,Sharepoint,Filestream,Memorystream,我试图在WCF3.5中使用REST样式的URL而不是SOAP返回流。其想法是从SharePoint 2010中读取一个文件,然后将其传递回客户端。(我们有理由这样做而不是使用SharePoint services,但我离题了。)似乎发送文件的唯一方法是使用一个FileStream将文件写入文件系统,然后使用file.OpenRead将流返回给客户端。使用MemoryStream似乎不起作用。IE提示保存文件,但文件的大小像2KB,当然无法读取,因为它不全在那里。有什么想法吗 SPListItem
FileStream
将文件写入文件系统,然后使用file.OpenRead
将流返回给客户端。使用MemoryStream
似乎不起作用。IE提示保存文件,但文件的大小像2KB,当然无法读取,因为它不全在那里。有什么想法吗
SPListItemCollection lookupFld2 = docLibrary.GetItems(spQuery2);
if (lookupFld2.Count > 0)
{
WebOperationContext.Current.OutgoingResponse.ContentType =
"application/octet-stream";
WebOperationContext.Current.OutgoingResponse.Headers.Add(
"Content-Disposition","attachment; filename=" + lookupFld2[0].File.Name);
MemoryStream memoryStream =
(MemoryStream)lookupFld2[0].File.OpenBinaryStream();
memoryStream.Position = 0;
return memoryStream;
}
从技术上讲,OpenBinaryStream只返回一般流实例,而不是MemoryStream(http://msdn.microsoft.com/en-us/library/ms470901.aspx). 如果需要MemoryStream,则需要创建一个新的MemoryStream,并将二进制流中的内容复制到MemoryStream中,然后重置位置并返回它