There could be times where one might need to download a file for processing in the server before rendering. May be for a file type conversion prior to rendering or so...During such instances this can be used. The below code block needs to be run within elevated privileges.
web.AllowUnsafeUpdates = true;
SPFile file = web.GetFile(fileUrl);
using (FileStream outStream = new FileStream("Specify the file Download location in server drive"), FileMode.Create))
{
byte[] obj = (byte[])file.OpenBinary();
outStream.Write(obj, 0, obj.Length);
}
web.AllowUnsafeUpdates = false;
Side Note:
You can specify the download location in the web.config <AppSettings> section and retrieved via:
ConfigurationManager.AppSettings["AppSettingName"].ToString();
web.AllowUnsafeUpdates = true;
SPFile file = web.GetFile(fileUrl);
using (FileStream outStream = new FileStream("Specify the file Download location in server drive"), FileMode.Create))
{
byte[] obj = (byte[])file.OpenBinary();
outStream.Write(obj, 0, obj.Length);
}
web.AllowUnsafeUpdates = false;
Side Note:
You can specify the download location in the web.config <AppSettings> section and retrieved via:
ConfigurationManager.AppSettings["AppSettingName"].ToString();
No comments:
Post a Comment