public string uploadSharePointFile() { string result = "success"; try { string Username = Decryption.DecryptNew(System.Configuration.ConfigurationManager.AppSettings["UserName"].ToString()); string Password = Decryption.DecryptNew(System.Configuration.ConfigurationManager.AppSettings["Password"].ToString()); var destpath = Path.Combine(HttpContext.Current.Server.MapPath("~/CSV/CurrentFile"), "Global_IT_Roadmap.xlsx"); WebClient webClient = new WebClient(); webClient.Credentials = new NetworkCredential(Username, Password); webClient.OpenRead(SharepointPath); webClient.DownloadFile(SharepointPath, destpath); //var archivefileName = "Global_IT_Roadmap" + "_" + DateTime.Now.ToString("MMddyyhhmm"); //var archivepath = Path.Combine(HttpContext.Current.Server.MapPath("~/CSV/Archive"), archivefileName + ".xlsx"); //webClient.DownloadFile(SharepointPath, archivepath); return(result); } catch (Exception ex) { writeLog(ex); result = ex.ToString(); return(result); } }
public string uploadSharePointFileByNetworkMethod() { string result = "success"; try { string Username = Decryption.DecryptNew(System.Configuration.ConfigurationManager.AppSettings["UserName"].ToString()); string Password = Decryption.DecryptNew(System.Configuration.ConfigurationManager.AppSettings["Password"].ToString()); var destpath = Path.Combine(HttpContext.Current.Server.MapPath("~/CSV/CurrentFile"), "Global_IT_Roadmap.xlsx"); var networkPath = SharepointPath; var credentials = new NetworkCredential(Username, Password); string[] fileList; //Try Method 1 to get files from sharepoint path using (new NetworkConnection(networkPath, credentials)) { fileList = Directory.GetFiles(networkPath); } //Try Method 2 to copy files from sharepoint path using (new NetworkConnection(networkPath, credentials)) { File.Copy(SharepointPath, destpath); } return(result); } catch (Exception ex) { writeLog(ex); result = ex.ToString(); return(result); } }