如何在 SharePoint 2010 托管代码中存储临时文件? [英] How to store temp files in SharePoint 2010 hosted code?

查看:48
本文介绍了如何在 SharePoint 2010 托管代码中存储临时文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 SharePoint 2010 中有一个托管 Web 服务,它可以上传和下载到 sharepoint.因为文件可能很大(100MB+),我更愿意使用临时文件作为代码通过的流而不是内存流,以避免每次下载/上传时分配 100MB 内存.

I have a hosted web service in SharePoint 2010 that does uploads and downloads to sharepoint. Because the files can be large (100MB+), i would much rather use temp files as the streams the code goes through instead of memory-streams to avoid 100mb memory allocations each time it does download/upload.

问题是我可以在服务器中找到一个位置来存储临时文件.System.IO.Path.GetTempFileName() 会引发错误,因为经过身份验证的用户无权访问服务器中的 %TEMP% 文件夹."%systemroot%\temp" 允许写入文件但不能删除它们.

The problem is that i could find a location in the server to store temp files. System.IO.Path.GetTempFileName() throws an error because the authenticated user doesn't have permissions to %TEMP% folder in the server. "%systemroot%\temp" allows writing files but not deleting them.

知道我是否可以从任何经过身份验证的用户都可以访问的共享点获取位置来存储文件吗?

Any idea if i can get a location from sharepoint that is accessible for any authenticated user to store the files?

注意事项:

  1. 文件是临时的,需要立即删除,因此无需考虑集群问题.

  1. the files are temporary and need to be deleted right away so no need to consider clustering issues.

我不想要一个需要在服务器中执行任何主动操作的解决方案,因为该插件可能部署在拥有大量服务器的农场上,我不想让客户通过每台服务器.

I don't want a solution that requires doing any active action in the servers as this plugin might be deployed on farms with a lot of servers and i'd hate to ask the customer to go through each server.

谢谢.

推荐答案

您需要访问 SharePoint 的系统帐户"下的文件.是的, System.IO.Path.GetTempFileName() 是正确的位置.

You need to access files under SharePoint's "system account". And yes, System.IO.Path.GetTempFileName() is correct location.

起点 - SPSecurity.RunWithElevatedPrivileges.

注意事项

  • 如果您可以将文件打开为临时 + 关闭时删除"(检查 FileStream 类中的相应标志).
  • 在 RunWithElevatedPrivileges 委托中运行代码时,请务必小心不要访问其他 SharePoint 资源(SPFile/SPItem...).
  • 您可能只需要在 RunWithElevatedPrivileges 下打开文件,读/写可能在外面工作 - 请验证自己.我会将所有文件访问权限保留在使用 RunWithElevatedPrivileges 运行的委托中.

这篇关于如何在 SharePoint 2010 托管代码中存储临时文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆