Reputation: 11
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.
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?
few notes:
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.
Thanks.
Upvotes: 1
Views: 2892
Reputation: 39
It might not be the best place but I have used the _layouts directory in the hive before (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS) for doing something similar to this before.
You can get this location with Microsoft.SharePoint.Utilities.SPUtility.GetGenericSetupPath() and you should be able to read/write in the directory. You may need to run as elevated permissions.
Upvotes: 0
Reputation: 100547
You need to access files under SharePoint's "system account". And yes, System.IO.Path.GetTempFileName() is correct location.
Starting point - SPSecurity.RunWithElevatedPrivileges.
Notes
Upvotes: 2