Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Saturday, 25 April 2015

Save file in local drive

try {
SPSecurity.RunWithElevatedPrivileges(delegate() { oFile = @"filepath"; byte[] binFile = oFile.OpenBinary(); string path = @"D:\Library\"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string tepmPath = path + oFile.Name; if (File.Exists(tepmPath)) { File.Delete(tepmPath); } using (FileStream fs = File.Create(tepmPath)) { fs.Write(binFile, 0, binFile.Length); fs.Close(); } }); }
catch (Exception ex)
{
//exception handleing here
}

Please provide your feedback in the comments section above. Please don't forget to follow.