Exemplo n.º 1
0
        public void AddFile(FileInfo file)
        {
            DataRow dr;

            dr = _Files.NewRow();
            dr["Chk"] = false;
            dr["Type"] = "F";
            dr["Name"] = file.Name;
            dr["Length"] = new Ultils().FormatFileSize(file.Length);
            dr["Updated"] = file.LastWriteTime;

            _Files.Rows.Add(dr);
        }
Exemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string currentPhysPath;
            LoadStateData();
            LocalizeControls();

            if (!Page.IsPostBack)
            {
                if (Request.QueryString["value"] != String.Empty)
                {
                    currentPath = Request.QueryString["value"];

                    if (!useAppRelPath)
                    {
                        currentPath = rootPath + currentPath +"Thang_" + DateTime.Now.Month + "/Ngay_" + DateTime.Now.Day + "/";
                    }

                    currentPhysPath = Server.MapPath(currentPath);

                    if (currentPath != null)
                    {
                        if (Directory.Exists(currentPhysPath))
                        {
                            currentPath = new Ultils().AddSlashInTheEndIfNotPresent(currentPath);
                        }
                        else if (File.Exists(currentPhysPath))
                        {
                            currentPath = new Ultils().AddSlashInTheEndIfNotPresent(new Ultils().GetParentDirectory(currentPath));
                        }
                        else
                        {
                            currentPath = rootPath + "Thang_" + DateTime.Now.Month + "/Ngay_" + DateTime.Now.Day + "/";
                        }
                    }
                    else
                    {
                        currentPath = rootPath + "Thang_" + DateTime.Now.Month + "/Ngay_" + DateTime.Now.Day + "/";
                    }
                }
                else
                {
                    currentPath = rootPath + "Thang_" + DateTime.Now.Month + "/Ngay_" + DateTime.Now.Day + "/";
                }

                Trace.Warn("rootPath=" + rootPath);
                Trace.Warn("currentPath=" + currentPath);
                Trace.Warn("UseAppRelPath=" + useAppRelPath.ToString());

                Reload();

                ShowInfo((string)this.GetGlobalResourceObject("Lang","LOC_LABEL_LAUNCHED"));
            }
        }
Exemplo n.º 3
0
        public string ZipFiles(ArrayList FileList, string PhysZipPath, string ZipFileName)
        {
            //'If there are no checked files then return

            string PhysZipFilePath = "";

            if (FileList.Count == 0)
            {
                return String.Empty;
            }

            //'If the directory to place Zip file doesn't exist, create it
            if (!Directory.Exists(PhysZipPath))
            {
                Directory.CreateDirectory(PhysZipPath);
            }

            //'Figure out full file name and path for the Zip file
            if (ZipFileName == String.Empty)
            {
                //'If name of the Zip file is not provided
                PhysZipFilePath = new Ultils().AddBackSlashInTheEndIfNotPresent(PhysZipPath) + Path.GetFileNameWithoutExtension(Convert.ToString(FileList[0])) + ".zip";
                int i = 0;
                //'If this name already exists, create an unique name
                while (File.Exists(PhysZipFilePath))
                {
                    i += 1;
                    PhysZipFilePath = new Ultils().AddBackSlashInTheEndIfNotPresent(PhysZipFilePath) + Path.GetFileNameWithoutExtension(Convert.ToString(FileList[0]) + "(" + i + ")" + ".zip");
                }
            }
            else
            {
                //'If name of the Zip file is provided,
                //'just construct physical path for the file
                PhysZipFilePath = new Ultils().AddBackSlashInTheEndIfNotPresent(PhysZipPath) + ZipFileName;
            }

            //'Create an empty zip file
            ZipWriter writer = new ZipWriter(PhysZipFilePath);

            //'Prepare a buffer to write
            Byte[] buffer = new Byte[4096];
            int byteCount = 0;
            FileStream reader = null;
            string filezipstore = "";
            ZipEntry entry;

            int k = 0;

            try
            {
                foreach (string Item in FileList)
                {
                    k += 1;
                    filezipstore = Item.Replace(Server.MapPath(currentPath), "");
                    entry = new ZipEntry(filezipstore);
                    entry.ModifiedTime = File.GetLastWriteTime(Item);
                    writer.AddEntry(entry);

                    try
                    {
                        reader = File.OpenRead(Item);

                        //'Read from file until the end and write it into zip file
                        byteCount = reader.Read(buffer, 0, buffer.Length);

                        while (byteCount > 0)
                        {
                            //'Write to file compress bytes
                            writer.Write(buffer, 0, byteCount);
                            byteCount = reader.Read(buffer, 0, buffer.Length);
                        }
                    }
                    finally
                    {
                        //'Close the file
                        reader.Close();
                    }
                }
            }
            catch (UnauthorizedAccessException ex)
            {
                ShowInfo((string)this.GetGlobalResourceObject("Lang","LOC_ERROR_ZIP_CANNOTCREATE_ACCESSDENIED"), MessageType.ErrorMsg);
                return "";
            }
            catch (ArgumentException ex)
            {
                ShowInfo((string)this.GetGlobalResourceObject("Lang","LOC_ERROR_ZIP_CANNOTCREATE_WRONGNAME"), MessageType.ErrorMsg);
                return "";
            }
            catch (Exception ex)
            {
                ShowInfo((string)this.GetGlobalResourceObject("Lang","LOC_ERROR_COPY_CANNOTCREATE") + " " + ex.Message, MessageType.ErrorMsg);
                return "";
            }
            finally
            {
                //'Close the zip file
                writer.Close();
            }

            return PhysZipFilePath;
        }
Exemplo n.º 4
0
        void ShowInfo(string msg, MessageType msgType)
        {
            string Path = System.Web.HttpContext.Current.Server.MapPath(currentPath);

            //if(!Directory.Exists(Path))
            //{
            //    Directory.CreateDirectory(Path);
            //}
            DirectoryInfo DirInfo = new DirectoryInfo(Path);

            int NumDir = 0;
            int NumFiles = 0;
            long size = 0;
            String Total = "";
            String message = "";

            foreach (DirectoryInfo directory in DirInfo.GetDirectories())
            {
                NumDir += 1;
            }

            foreach (FileInfo file in DirInfo.GetFiles())
            {
                NumFiles += 1;
                size += file.Length;
            }

            if (size < 1)
            {
                if (NumFiles > 0)
                {
                    size = 1;
                }
                else
                {
                    size = 0;
                }
            }

            if (size == 0)
            {
                Total = "0 " + (string)this.GetGlobalResourceObject("Lang","LOC_LABEL_KB");
            }
            else
            {
                Total = new Ultils().FormatFileSize(size);
            }

            //'Build full version of info string
            message = msg;

            if (message != "")
            {
                message = message + "<BR>";
            }

            switch (msgType)
            {
                case MessageType.InfoMsg:
                    message = "<b>" + (string)this.GetGlobalResourceObject("Lang","LOC_LABEL_ACTION") + ":</b> " + message + " ";
                    break;
                case MessageType.ErrorMsg:
                    message = "<font class='ErrorMessage'><b>" + (string)this.GetGlobalResourceObject("Lang","LOC_LABEL_ERROR") + ":</b> " + message + "</font>";
                    break;
            }
            Info.Text = message + "<b>" + (string)this.GetGlobalResourceObject("Lang","LOC_LABEL_DIRS") + "</b> " + NumDir + " | <b>" + (string)this.GetGlobalResourceObject("Lang","LOC_LABEL_FILES") + ":</b> " +
                                 NumFiles + " | <b>" + (string)this.GetGlobalResourceObject("Lang","LOC_LABEL_TOTAL") + "</b> " + Total;

            //'If show an error, show also a message box
            if (msgType == MessageType.ErrorMsg)
            {
                wmbMessage.Enabled = true;
                wmbMessage.MessageBoxTitle = (string)this.GetGlobalResourceObject("Lang","LOC_LABEL_ERROR");
                //'Because the Web MessageBox component emits code in VBScript,
                //'we need to prevent double quotes from being considered as
                //'language elements. So, replace them with single quotes.
                wmbMessage.MessageBoxText = msg.Replace("\"\"", "'");
            }
        }
Exemplo n.º 5
0
        protected void NavigateUp(Object sender, ImageClickEventArgs e)
        {
            string proposedCurrentPath;

            dgExplorer.EditItemIndex = -1;

            if (currentPath != rootPath)
            {
                proposedCurrentPath = new Ultils().GetParentDirectory(currentPath);
                proposedCurrentPath = new Ultils().AddSlashInTheEndIfNotPresent(proposedCurrentPath);
                if (proposedCurrentPath == String.Empty)
                {
                    proposedCurrentPath = rootPath;
                }
                currentPath = proposedCurrentPath;
            }

            Reload();

            ShowInfo((string)this.GetGlobalResourceObject("Lang","LOC_LABEL_MOVEDONEFOLDERUP"));
        }
Exemplo n.º 6
0
        void Reload()
        {
            Explorer Expl;
            string FullPhysThumbPath = "";

            //'Delete temporary directory
            string TempPhysPath = new Ultils().AddBackSlashInTheEndIfNotPresent(Server.MapPath(rootPath)) + tempPath;
            if (Directory.Exists(TempPhysPath))
            {
                Directory.Delete(TempPhysPath, true);
            }

            //'Create thumbnail direcotry if thumbnails enabled
            if (showThumbnails)
            {
                FullPhysThumbPath = Request.MapPath(new Ultils().AddSlashInTheEndIfNotPresent(currentPath) + thumbPath);

                if (!Directory.Exists(FullPhysThumbPath))
                {
                    try
                    {
                        Directory.CreateDirectory(FullPhysThumbPath);
                    }
                    catch (UnauthorizedAccessException ex)
                    {
                        ShowInfo((string)this.GetGlobalResourceObject("Lang","LOC_ERROR_CREATE_THUMBNAIL_ACCESSDENIED"), MessageType.ErrorMsg);
                        return;
                    }
                    catch (Exception ex)
                    {
                        ShowInfo((string)this.GetGlobalResourceObject("Lang","LOC_ERROR_CREATE_THUMBNAIL") + " " + ex.Message, MessageType.ErrorMsg);
                        return;
                    }
                }
            }

            //'Prepare path to display
            string DisplayPath = currentPath;

            //'Hide root (upload folder) path
            //'Don't let remove all slashes from the path string
            //'if root path is the web server root [/]
            if (rootPath.Trim() == "/")
            {
                DisplayPath = DisplayPath.Replace(rootPath, String.Empty);
            }

            //'Ensure that a slash is present in the beginning of the path to display
            if (DisplayPath == String.Empty)
            {
                DisplayPath = "/";
            }
            else
            {
                if (!DisplayPath.StartsWith("/"))
                {
                    DisplayPath = "/" + DisplayPath;
                }
            }

            //'Show the current path
            txtCurrentPath.Text = DisplayPath;

            //'Read the Directories and Files and show them in the datagrid
            try
            {
                Expl = new Explorer(currentPath);
                Expl.Files.DefaultView.Sort = sortField + " " + sortDirection;
                dgExplorer.DataSource = Expl.Files.DefaultView;
                dgExplorer.DataBind();
            }
            catch (UnauthorizedAccessException ex)
            {
                ShowInfo((string)this.GetGlobalResourceObject("Lang","LOC_ERROR_READLIST_ACCESSDENIED"), MessageType.ErrorMsg);
            }
            catch (Exception ex)
            {
                ShowInfo((string)this.GetGlobalResourceObject("Lang","LOC_ERROR_READLIST") + " " + ex.Message, MessageType.ErrorMsg);
            }
        }
Exemplo n.º 7
0
        void SaveUploadedFile()
        {
            if (!(inputFileName.PostedFile == null))
            {
                try
                {
                    string strPath = Server.MapPath(currentPath);

                    string FileName = new Ultils().AddBackSlashInTheEndIfNotPresent(strPath) + Path.GetFileName(inputFileName.PostedFile.FileName);

                    //'Delete the file if already exists but overwriting is not
                    //'disabled
                    if (File.Exists(FileName))
                    {
                        if (chkOverwrite.Checked)
                        {
                            FileInfo fi = new FileInfo(FileName);
                            fi.Delete();
                        }
                        else
                        {
                            ShowInfo(String.Format((string)this.GetGlobalResourceObject("Lang","LOC_ERROR_UPLOAD_FILEEXISTS"), inputFileName.PostedFile.FileName), MessageType.ErrorMsg);
                            return;
                        }
                    }

                    //'Save the uploaded file
                    inputFileName.PostedFile.SaveAs(FileName);

                    //'Get the file extension
                    string Extension = (Path.GetExtension(FileName)).ToLower();

                    //'If extension is .zip then extract the archive
                    if (Extension == ".zip")
                    {
                        int i = 0;

                        switch (rblUploadOptions.SelectedIndex)
                        {
                            case 0:
                                //'Unzip + Delete
                                i = UnZip(FileName, true);
                                File.Delete(FileName);
                                //'Show the last action on server
                                ShowInfo(String.Format((string)this.GetGlobalResourceObject("Lang", "LOC_LABEL_1FILEUPLOADEDWITHFILES"), i.ToString()));
                                break;
                            case 1:
                                //'Unzip the file
                                i = UnZip(FileName, true);
                                //'Show the last action on server
                                ShowInfo(String.Format((string)this.GetGlobalResourceObject("Lang", "LOC_LABEL_1FILEUPLOADEDWITHFILES"), i.ToString()));
                                break;
                            case 2:
                                //'Only upload
                                //'Show the last action to user
                                ShowInfo((string)this.GetGlobalResourceObject("Lang","LOC_LABEL_1FILEUPLOADED"));

                                //'Select the file and close the window if user
                                //'needs it
                                if (chkSelectUponUpload.Checked)
                                {
                                    SelectFile(Path.GetFileName(inputFileName.PostedFile.FileName));
                                }
                                break;
                        }
                    }
                    else
                    {
                        //'Show the last action to user
                        ShowInfo((string)this.GetGlobalResourceObject("Lang","LOC_LABEL_1FILEUPLOADED"));

                        //'Select the file and close the window if user
                        //'needs it
                        if (chkSelectUponUpload.Checked)
                        {
                            SelectFile(Path.GetFileName(inputFileName.PostedFile.FileName));
                        }
                    }
                }
                catch (UnauthorizedAccessException ex)
                {
                    ShowInfo((string)this.GetGlobalResourceObject("Lang","LOC_ERROR_UPLOAD_ACCESSDENIED"), MessageType.ErrorMsg);
                }
                catch (Exception ex)
                {
                    ShowInfo((string)this.GetGlobalResourceObject("Lang","LOC_ERROR_UPLOAD") + " " + ex.Message, MessageType.ErrorMsg);
                }
            }
        }
Exemplo n.º 8
0
        void PasteCopyFiles()
        {
            long k;
            k = 0;

            foreach (string Item in fileList)
            {
                string PathFrom;
                PathFrom = new Ultils().AddBackSlashInTheEndIfNotPresent(Server.MapPath(pathCopy)) + Item;

                string PathTo;
                PathTo = new Ultils().AddBackSlashInTheEndIfNotPresent(Server.MapPath(currentPath)) + Item;
                Trace.Warn("PathFrom = " + PathFrom);
                Trace.Warn("PathTo = " + PathTo);

                if (!IsRecursive(PathFrom, PathTo))
                {
                    if (File.Exists(PathFrom))
                    {
                        if (!File.Exists(PathTo))
                        {
                            try
                            {
                                File.Copy(PathFrom, PathTo);
                            }
                            catch (UnauthorizedAccessException ex)
                            {
                                ShowInfo(String.Format((string)this.GetGlobalResourceObject("Lang","LOC_ERROR_COPY_FILE_ACCESSDENIED"), Item), MessageType.ErrorMsg);
                                return;
                            }

                            catch (Exception ex)
                            {
                                ShowInfo(String.Format((string)this.GetGlobalResourceObject("Lang","LOC_ERROR_COPY_FILE"), Item) + " " + ex.Message, MessageType.ErrorMsg);
                                return;
                            }
                        }
                        else
                        {

                            int i = 0;
                            while (File.Exists(PathTo))
                            {
                                i += 1;
                                PathTo = Server.MapPath(currentPath) + Path.GetFileNameWithoutExtension(Item) + " " + (string)this.GetGlobalResourceObject("Lang","LOC_PREFIX_THECOPY") + " (" + i + ")" + Path.GetExtension(Item);
                            }

                            try
                            {
                                File.Copy(PathFrom, PathTo);
                            }
                            catch (UnauthorizedAccessException ex)
                            {
                                ShowInfo(String.Format((string)this.GetGlobalResourceObject("Lang","LOC_ERROR_COPY_FILE_ACCESSDENIED"), Item), MessageType.ErrorMsg);
                                return;
                            }
                            catch (Exception ex)
                            {
                                ShowInfo(String.Format((string)this.GetGlobalResourceObject("Lang","LOC_ERROR_COPY_FILE"), Item) + " " + ex.Message, MessageType.ErrorMsg);
                                return;
                            }
                        }
                    }
                    if (Directory.Exists(PathFrom))
                    {
                        try
                        {
                            CopyDirectory(PathFrom, PathTo);
                        }
                        catch (UnauthorizedAccessException ex)
                        {
                            ShowInfo(String.Format((string)this.GetGlobalResourceObject("Lang","LOC_ERROR_COPY_DIRECTORY_ACCESSDENIED"), Item), MessageType.ErrorMsg);
                            return;
                        }
                        catch (Exception ex)
                        {
                            ShowInfo(String.Format((string)this.GetGlobalResourceObject("Lang","LOC_ERROR_COPY_DIRECTORY"), Item) + " " + ex.Message, MessageType.ErrorMsg);
                            return;
                        }
                    }
                    k += 1;
                }
            }
            ShowInfo(k.ToString() + " " + (string)this.GetGlobalResourceObject("Lang","LOC_LABEL_FILESPASTED"));
        }
Exemplo n.º 9
0
        void PasteCutFiles()
        {
            int k = 0;

            foreach (string Item in fileList)
            {

                string PathFrom = new Ultils().AddBackSlashInTheEndIfNotPresent(Server.MapPath(pathCopy)) + Item;

                string PathTo = new Ultils().AddBackSlashInTheEndIfNotPresent(Server.MapPath(currentPath)) + Item;

                if (PathFrom == PathTo)
                {
                    return;
                }

                if (File.Exists(PathFrom))
                {

                    try
                    {
                        if (File.Exists(PathTo))
                        {
                            File.Delete(PathTo);
                        }

                        File.Move(PathFrom, PathTo);
                    }
                    catch (UnauthorizedAccessException ex)
                    {
                        ShowInfo(String.Format((string)this.GetGlobalResourceObject("Lang","LOC_ERROR_MOVE_FILE_ACCESSDENIED"), Item), MessageType.ErrorMsg);
                        return;
                    }
                    catch (Exception ex)
                    {
                        ShowInfo(String.Format((string)this.GetGlobalResourceObject("Lang","LOC_ERROR_MOVE_FILE"), Item) + " " + ex.Message, MessageType.ErrorMsg);
                        return;
                    }
                }
                else
                {

                    if (Directory.Exists(PathFrom))
                    {

                        try
                        {

                            bool Continue = true;

                            if (Directory.Exists(PathTo))
                            {
                                if (!IsRecursive(PathTo, PathFrom))
                                {
                                    Directory.Delete(PathTo, true);
                                }
                                else
                                {
                                    Continue = false;
                                    k -= 1;
                                }
                            }
                            if (Continue)
                            {

                                Directory.Move(PathFrom, PathTo);

                            }
                        }
                        catch (UnauthorizedAccessException ex)
                        {
                            ShowInfo(String.Format((string)this.GetGlobalResourceObject("Lang","LOC_ERROR_MOVE_DIRECTORY_ACCESSDENIED"), Item), MessageType.ErrorMsg);
                            return;
                        }
                        catch (Exception ex)
                        {
                            ShowInfo(String.Format((string)this.GetGlobalResourceObject("Lang","LOC_ERROR_MOVE_DIRECTORY"), Item) + " " + ex.Message, MessageType.ErrorMsg);
                            return;
                        }
                    }
                }
                k += 1;
            }

            ShowInfo(k.ToString() + " " + (string)this.GetGlobalResourceObject("Lang","LOC_LABEL_FILESPASTED"));
        }
Exemplo n.º 10
0
        private void LoadStateData()
        {
            fPTextBoxID = Request.QueryString["TextBoxID"];

            if (!Page.IsPostBack)
            {

                if (Session[fPTextBoxID + "fpUploadDir"] == null)
                {
                    Response.Write("<script language='JavaScript'>alert('" + ((string)this.GetGlobalResourceObject("Lang","LOC_ERROR_SESSIONEMPTY")).Replace("'", "\'") + "');window.close();</script>");
                    Response.Flush();
                    Response.End();
                }

                if (Session[fPTextBoxID + "fpAllowedUploadFileExts"] != null) allowedUploadFileExts = Convert.ToString(Session[fPTextBoxID + "fpAllowedUploadFileExts"]);
                if (Session[fPTextBoxID + "fpUploadSizeLimit"] != null) uploadSizeLimit = Convert.ToInt64(Session[fPTextBoxID + "fpUploadSizeLimit"]);
                if (Session[fPTextBoxID + "fpAllowUpload"] != null) allowUpload = Convert.ToBoolean(Session[fPTextBoxID + "fpAllowUpload"]);
                if (Session[fPTextBoxID + "fpAllowCreateDirs"] != null) allowCreateDirs = Convert.ToBoolean(Session[fPTextBoxID + "fpAllowCreateDirs"]);
                if (Session[fPTextBoxID + "fpAllowDelete"] != null) allowDelete = Convert.ToBoolean(Session[fPTextBoxID + "fpAllowDelete"]);
                if (Session[fPTextBoxID + "fpAllowRename"] != null) allowRename = Convert.ToBoolean(Session[fPTextBoxID + "fpAllowRename"]);
                if (Session[fPTextBoxID + "fpAllowChangeLanguage"] != null) allowChangeLanguage = Convert.ToBoolean(Session[fPTextBoxID + "fpAllowChangeLanguage"]);
                if (Session[fPTextBoxID + "fpAllowCopy"] != null) allowCopy = Convert.ToBoolean(Session[fPTextBoxID + "fpAllowCopy"]);
                if (Session[fPTextBoxID + "fpAllowMove"] != null) allowMove = Convert.ToBoolean(Session[fPTextBoxID + "fpAllowMove"]);
                if (Session[fPTextBoxID + "fpUseAppRelPath"] != null) useAppRelPath = Convert.ToBoolean(Session[fPTextBoxID + "fpUseAppRelPath"]);
                if (Session[fPTextBoxID + "fpUploadDir"] != null) rootPath = Convert.ToString(Session[fPTextBoxID + "fpUploadDir"]);
            }
            else
            {
                allowedUploadFileExts = Convert.ToString(ViewState["fpAllowedUploadFileExts"]);
                uploadSizeLimit = Convert.ToInt32(ViewState["fpUploadSizeLimit"]);
                allowUpload = Convert.ToBoolean(ViewState["fpAllowUpload"]);
                allowCreateDirs = Convert.ToBoolean(ViewState["fpAllowCreateDirs"]);
                allowDelete = Convert.ToBoolean(ViewState["fpAllowDelete"]);
                allowRename = Convert.ToBoolean(ViewState["fpAllowRename"]);
                allowChangeLanguage = Convert.ToBoolean(ViewState["fpAllowChangeLanguage"]);
                allowCopy = Convert.ToBoolean(ViewState["fpAllowCopy"]);
                allowMove = Convert.ToBoolean(ViewState["fpAllowMove"]);
                useAppRelPath = Convert.ToBoolean(ViewState["fpUseAppRelPath"]);

            }

            if (Page.IsPostBack)
            {
                if (ViewState["rootPath"] != null) rootPath = (string)(ViewState["rootPath"]);
                if (ViewState["currentPath"] != null) currentPath = (string)(ViewState["currentPath"]);

                if (ViewState["rowToSelect"] != null) rowToSelect = (string)(ViewState["rowToSelect"]);
                if (ViewState["foundFiles"] != null) foundFiles = (ArrayList)(ViewState["foundFiles"]);
                if (ViewState["pathCopy"] != null) pathCopy = (string)(ViewState["pathCopy"]);
                if (ViewState["operation"] != null) operation = (string)(ViewState["operation"]);
                if (ViewState["fileList"] != null) fileList = (ArrayList)(ViewState["fileList"]);
                if (ViewState["currentPathAux"] != null) currentPathAux = (string)(ViewState["currentPathAux"]);
                if (ViewState["rootPathAux"] != null) rootPathAux = (string)(ViewState["rootPathAux"]);
                if (ViewState["fileToRename"] != null) fileToRename = (string)(ViewState["fileToRename"]);
                if (ViewState["sortField"] != null) sortField = (string)(ViewState["sortField"]);
                if (ViewState["sortDirection"] != null) sortDirection = (string)(ViewState["sortDirection"]);
                if (ViewState["showThumbnails"] != null) showThumbnails = Convert.ToBoolean(ViewState["showThumbnails"]);
            }

            if (rootPath == null || rootPath == String.Empty)
            {
                rootPath = "/";
            }
            rootPath = new Ultils().AddSlashInTheEndIfNotPresent(rootPath);

            if (currentPath == null || currentPath == String.Empty)
            {
                currentPath = rootPath;
            }

            if (sortField == null || sortField == String.Empty)
            {
                sortField = "Name";
            }

            if (sortDirection == null || sortDirection == String.Empty)
            {
                sortDirection = "ASC";
            }

            allowedUploadFileExts = allowedUploadFileExts.Trim();
        }
Exemplo n.º 11
0
        void DownloadItem(string Filename)
        {
            String PhysFilePath = "";
            String ZipFileName = "";
            String PhysZipFileName = "";
            ArrayList FileList = new ArrayList();

            //'Figure out the full path for the file/folder
            string CurrentPhysPath = Server.MapPath(currentPath);
            CurrentPhysPath = new Ultils().AddBackSlashInTheEndIfNotPresent(CurrentPhysPath);
            PhysFilePath = CurrentPhysPath + Filename;

            //'Check what we're downloading -- a file or a folder
            if (File.Exists(PhysFilePath))
            {
                //'Download a file
                //'Send the file to the client
                SendFileToClient(PhysFilePath);
            }
            else if (Directory.Exists(PhysFilePath))
            {
                //'Download a folder
                //'Zip (compress) the folder and all the subfolders and send the
                //'archive to the client
                FileList.AddRange(GetFileList(PhysFilePath, "*.*"));
                ZipFileName = Filename + ".zip";
                PhysZipFileName = ZipFiles(FileList, CurrentPhysPath + tempPath, ZipFileName);
                if (FileList.Count > 0)
                {
                    if (PhysZipFileName != string.Empty)
                    {
                        //'Send the Zip file to user
                        SendFileToClient(PhysZipFileName);
                    }
                }
                else
                {
                    ShowInfo((string)this.GetGlobalResourceObject("Lang","LOC_ERROR_NOFILESTOCOMPRESS"), MessageType.ErrorMsg);
                }
            }
        }
Exemplo n.º 12
0
        private void DeleteFiles()
        {
            string strPath = Server.MapPath(currentPath);
            string targetFolder = new Ultils().AddBackSlashInTheEndIfNotPresent(strPath);

            DirectoryInfo targetDir = new DirectoryInfo(targetFolder);

            try
            {
                foreach (FileInfo file in targetDir.GetFiles())
                {
                    if ((file.Attributes & FileAttributes.ReadOnly) == 0)
                    {
                        file.Delete();
                    }
                }
            }
            catch (IOException e)
            {
            }
        }
Exemplo n.º 13
0
        private void BindValidResults()
        {
            if (upload1.UploadedFiles.Count > 0)
            {
                foreach (UploadedFile validFile in upload1.UploadedFiles)
                {
                    string strPath = Server.MapPath(currentPath);
                    string FileName = new Ultils().AddBackSlashInTheEndIfNotPresent(strPath) + validFile.GetName();

                    //'Delete the file if already exists but overwriting is not
                    //'disabled
                    if (File.Exists(FileName))
                    {
                        if (chkOverwrite.Checked)
                        {
                            FileInfo fi = new FileInfo(FileName);
                            fi.Delete();
                        }
                        else
                        {
                            ShowInfo(String.Format((string)this.GetGlobalResourceObject("Lang", "LOC_ERROR_UPLOAD_FILEEXISTS"), validFile.GetName()), MessageType.ErrorMsg);
                            return;
                        }
                    }
                    validFile.SaveAs(FileName, true);
                    if (FileName.ToLower().IndexOf(".zip") > 0)
                    {
                        ZipUtil.UnZipFiles(FileName, strPath, "", true);
                    }
                }

                labelNoResults.Visible = false;
                repeaterValidResults.Visible = true;
                repeaterValidResults.DataSource = upload1.UploadedFiles;
                repeaterValidResults.DataBind();
                Reload();
            }
            else
            {
                labelNoResults.Visible = true;
                repeaterValidResults.Visible = false;
            }
        }
Exemplo n.º 14
0
        protected void Update(Object sender, DataGridCommandEventArgs e)
        {
            if( allowRename )
            {
                //'Get the new name
                string NewName = "";
                TextBox txtName = (TextBox) e.Item.FindControl("Name");
                NewName = txtName.Text.ToLower();

                //'Make a list with forbidden names in Windows
                string ForbiddenNames = "";
                ForbiddenNames = "aux;con;com1;com2;com3;com4;prn;lpt1;lpt2;";

                //'If the new name is in the forbidden list, do nothing
                //'and exit the procedure
                if( ForbiddenNames.IndexOf(NewName + ";") > 0 )
                {
                    dgExplorer.EditItemIndex = -1;
                    ShowInfo((string)this.GetGlobalResourceObject("Lang","LOC_ERROR_NOTVALIDNAME"), MessageType.ErrorMsg);
                    Reload();
                    return;
                }

                //'Get the current path
                string Path = "";
                Path = Server.MapPath(currentPath);

                //'Get the old file or directory name

                string OldName = new Ultils().AddBackSlashInTheEndIfNotPresent(Path) + fileToRename;

                //'Figure out the full path for the new name
                NewName = new Ultils().AddBackSlashInTheEndIfNotPresent(Path) + txtName.Text;

                //'Check if the file extension is in the list of forbidden
                //'extensions
                if( File.Exists(OldName) )
                {
                        //'ensure this is a file, not a folder
                    if(!IsAllowedFileType(System.IO.Path.GetExtension(NewName)) )
                    {
                        dgExplorer.EditItemIndex = -1;
                        ShowInfo((string)this.GetGlobalResourceObject("Lang","LOC_ERROR_INVALIDEXTENSION"), MessageType.ErrorMsg);
                        Reload();
                        return;
                    }
                }

                //'If the directory or the file exists, try to change the name
                if( File.Exists(OldName) )
                {
                    try
                    {
                        File.Move(OldName, NewName);
                        ShowInfo((string)this.GetGlobalResourceObject("Lang","LOC_LABEL_1FILERENAMED"));
                    }
                    catch(UnauthorizedAccessException ex)
                    {
                        ShowInfo((string)this.GetGlobalResourceObject("Lang","LOC_ERROR_RENAME_FILE_ACCESSDENIED"), MessageType.ErrorMsg);
                    }
                    catch(Exception ex)
                    {
                        ShowInfo((string)this.GetGlobalResourceObject("Lang","LOC_ERROR_RENAMINGFILE") + " " + ex.Message, MessageType.ErrorMsg);
                    }
                }
                else if (Directory.Exists(OldName) )
                {
                    try
                    {

                        Directory.Move(OldName, NewName);
                        ShowInfo((string)this.GetGlobalResourceObject("Lang","LOC_LABEL_1DIRECTORYRENAMED"));
                    }
                    catch(UnauthorizedAccessException exception)
                    {
                        ShowInfo((string)this.GetGlobalResourceObject("Lang","LOC_ERROR_RENAME_DIRECTORY_ACCESSDENIED"), MessageType.ErrorMsg);
                    }
                    catch(Exception ex)
                    {
                        ShowInfo((string)this.GetGlobalResourceObject("Lang","LOC_ERROR_RENAME_DIRECTORY") + " " + ex.Message, MessageType.ErrorMsg);
                    }
                }
            }

            //'Leave edit mode
            dgExplorer.EditItemIndex = -1;
            Reload();
        }