protected void Page_Load(object sender, EventArgs e) { if (CheckAuthentication()) { string strFileName = Path.GetFileName(HttpContext.Current.Request.Files[0].FileName); string url = Request.Url.ToString(); int folderId = int.Parse(Session[SageFrame.Common.SessionKeys.FolderID].ToString()); string strBaseLocation = string.Empty; if (Session[SageFrame.Common.SessionKeys.Path] != null) { strBaseLocation = Session[SageFrame.Common.SessionKeys.Path].ToString(); } string absolutePath = GetAbsolutePath(strBaseLocation); try { string strSaveLocation = absolutePath + strFileName; if (!File.Exists(strSaveLocation)) { HttpContext.Current.Request.Files[0].SaveAs(strSaveLocation); File.SetAttributes(strSaveLocation, FileAttributes.Archive); } CacheHelper.Clear("FileManagerFileList"); } catch (Exception ex) { fb.ProcessException(ex); } } }
protected void Page_Load(object sender, EventArgs e) { if (CheckAuthentication()) { string strFileName = Path.GetFileName(HttpContext.Current.Request.Files[0].FileName); string url = Request.Url.ToString(); int folderId = int.Parse(Session[SageFrame.Common.SessionKeys.FolderID].ToString()); string strBaseLocation = string.Empty; if (Session[SageFrame.Common.SessionKeys.Path] != null) { strBaseLocation = Session[SageFrame.Common.SessionKeys.Path].ToString(); } string absolutePath = GetAbsolutePath(strBaseLocation); try { try { System.Drawing.Image img = System.Drawing.Image.FromStream(HttpContext.Current.Request.Files[0].InputStream, true, true); } catch (Exception) { //retMsg = "LargeImagePixel"; //context.Response.ContentType = "text/plain"; //context.Response.Write(retMsg); return; } string strSaveLocation = absolutePath + strFileName; if (!File.Exists(strSaveLocation)) { HttpContext.Current.Request.Files[0].SaveAs(strSaveLocation); File.SetAttributes(strSaveLocation, FileAttributes.Archive); } CacheHelper.Clear("FileManagerFileList"); } catch (Exception ex) { fb.ProcessException(ex); } } }
public static string GetFileList(string filePath, int folderId, int UserID, int IsSort, int CurrentPage, int PageSize, int portalID, string userName, int userModuleID, string secureToken) { StringBuilder sb = new StringBuilder(); AuthenticateService objService = new AuthenticateService(); if (objService.IsPostAuthenticatedView(portalID, userModuleID, userName, secureToken)) { System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(filePath); List <ATTFile> lstFiles = new List <ATTFile>(); if (filePath == "/") { filePath = HttpContext.Current.Server.MapPath("~/"); } try { if (Directory.Exists(filePath)) { DirectoryInfo dirInfo = new DirectoryInfo(filePath); foreach (FileInfo file in dirInfo.GetFiles()) { ATTFile obj = new ATTFile(); obj.FileName = file.Name; obj.Folder = file.Directory.ToString(); obj.Size = int.Parse(file.Length.ToString()); obj.Extension = file.Extension; lstFiles.Add(obj); } } } catch (Exception ex) { fb.ProcessException(ex); } if (IsSort == 1) { SortList(ref lstFiles); } Dictionary <string, string> dictImages = GetImages(); if (lstFiles.Count > 0) { lstFiles = lstFiles.GetRange(GetStartRange(CurrentPage, PageSize), GetEndRange(CurrentPage, PageSize, lstFiles.Count)); ///Get the dictionary of images used in buttons sb.Append("<div class='sfGridwrapper'><table width='100%' cellspacing='0' cellpadding='0' class=\"jqueryFileTree\" id=\"fileList\">\n"); if (lstFiles.Count > 0 && HttpContext.Current.Session["SortDir"] == null || (string)HttpContext.Current.Session["SortDir"] == "asc") { sb.Append("<tr><th><span class='selectAll'><input type='checkbox' id='chkSelectAll'/></span></th><th><span class='fileName'>FileName <i class='icon-ascending-order' id='imgSort'></i></span></th><th><span class='fileInfo'>FileInfo</span></th><th class='sfEdit'></th><th class='sfEdit'></th><th class='sfEdit'></th></tr>"); } else if (lstFiles.Count > 0 && (string)HttpContext.Current.Session["SortDir"] == "desc") { sb.Append("<tr><th><span class='selectAll'><input type='checkbox' id='chkSelectAll'/></span></th><th><span class='fileName'>FileName <i class='icon-descending-order' id='imgSort' ></i></span></th><th><span class='fileInfo'>FileInfo</span></th><th class='sfEdit'></th><th class='sfEdit'></th><th class='sfEdit'></th></tr>"); } } if (lstFiles.Count == 0) { sb.Append("<div class='sfEmptyrow'>No Files</div>"); } string downloadPath = FileManagerHelper.ReplaceBackSlash(Path.Combine(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority), GetRelativePath("Modules/FileManager/DownloadHandler.ashx?"))); // string urlPath = GetUrlPath(filePath); string urlPath = GetPreviewUrlPath(filePath); string absolutePath = FileManagerHelper.ReplaceBackSlash(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath.ToString(), filePath)); int index = 0; foreach (ATTFile fi in lstFiles) { string ext = ""; bool IsZip = false; bool IsImg = false; if (fi.Extension.Length > 1) { ext = fi.Extension.Substring(1).ToLower(); } if (ext == "zip") { IsZip = true; } if (ext == "png" || ext == "gif" || ext == "jpg" || ext == "jpeg") { IsImg = true; } string checkId = "chk_" + fi.FileId; try { FileManagerHelper.ConstructHTMLString(IsZip, IsImg, fi.StorageLocation, ext, urlPath + fi.FileName, Path.Combine(absolutePath, fi.FileName), downloadPath, checkId, folderId, fi, ref sb, "edit", dictImages, index, secureToken); } catch (Exception ex) { fb.ProcessException(ex); } index++; } sb.Append("</table></div>"); sb.Append("<div id='divBottomControl'>"); sb.Append("</div>"); } return(sb.ToString()); }
protected void Page_Load(object sender, EventArgs e) { string strFileName = Path.GetFileName(HttpContext.Current.Request.Files[0].FileName); string strExtension = Path.GetExtension(HttpContext.Current.Request.Files[0].FileName).ToLower() == "resources" ? Path.GetExtension(HttpContext.Current.Request.Files[0].FileName.Replace("resources", "")).ToLower() : Path.GetExtension(HttpContext.Current.Request.Files[0].FileName).ToLower(); string url = Request.Url.ToString(); int folderId = int.Parse(Session["FolderID"].ToString()); string strBaseLocation = ""; if (Session["Path"] != null) { strBaseLocation = Session["Path"].ToString(); } string absolutePath = GetAbsolutePath(strBaseLocation); if (!Directory.Exists(absolutePath)) { Directory.CreateDirectory(absolutePath); } try { string strSaveLocation = absolutePath + strFileName; List <Folder> lstFolder = FileManagerController.GetFolders(); int saveMode = 0;///the standard mode ///check the folder file system to decide what to do with the file i.e. the saving mode of file int index = lstFolder.FindIndex( delegate(Folder fObj) { return(fObj.FolderId == folderId); } ); if (index > -1) { saveMode = lstFolder[index].StorageLocation; } switch (saveMode) { case 0: if (!File.Exists(strSaveLocation)) { HttpContext.Current.Request.Files[0].SaveAs(strSaveLocation); File.SetAttributes(strSaveLocation, FileAttributes.Archive); AddFileToDatabase(strFileName, strExtension, strBaseLocation, folderId, false, saveMode); } break; case 1: if (!File.Exists(strSaveLocation)) { HttpContext.Current.Request.Files[0].SaveAs(strSaveLocation + ".resources"); File.SetAttributes(strSaveLocation + ".resources", FileAttributes.Archive); AddFileToDatabase(strFileName, strExtension, strBaseLocation, folderId, false, saveMode); } break; case 2: if (!File.Exists(strSaveLocation)) { HttpContext.Current.Request.Files[0].SaveAs(strSaveLocation); AddFileToDatabase(strFileName, strExtension, strBaseLocation, folderId, true, saveMode); } break; } CacheHelper.Clear("FileManagerFileList"); } catch (Exception ex) { fb.ProcessException(ex); } }