我正在尝试将文件从共享点检索到本地硬盘。
这是我的代码:
SPFile file = web.GetFile("http://localhost/Basics.pptx");
byte[] data = file.OpenBinary();
FileStream fs = new FileStream(@"C:\Users\krg\Desktop\xyz.pptx",FileMode.Create,FileAccess.Write);
BinaryWriter w = new BinaryWriter(fs);
w.Write(data, 0, (int)file.Length);
w.Close();
fs.Close();
当我尝试打开该文件时,它显示为已损坏的文件。
The original file size is 186kb, after download the file size is 191kb.
从sharepoint..下载文件的解决方案是什么?
最佳答案
只是对这个答案的一点贡献。最好检查每个 block 中读取的字节数,以便写入的流与从 SharePoint 读取的流完全相同。 请参阅下面的更正。
int size = 10 * 1024;
using (Stream stream = file.OpenBinaryStream())
{
using (FileStream fs = new FileStream(@"C:\Users\krg\Desktop\xyz.pptx", FileMode.Create, FileAccess.Write))
{
byte[] buffer = new byte[size];
int nbBytesRead =0;
while((nbBytesRead=stream.Read(buffer, 0, buffer.Length)) > 0)
{
fs.Write(buffer, 0, nBytesRead);
}
}
}
关于c# - 将 SPFile 保存到本地硬盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5270104/