Exemple #1
0
        /// <summary>
        /// Deletes the specified sender.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.CommandEventArgs"/> instance containing the event data.</param>
        void Delete(object sender, CommandEventArgs e)
        {
            string file = e.CommandArgument.ToString();

            FileInfo fi = new FileInfo(file);

            // Determine type: folder or file.
            if (fi.Attributes == FileAttributes.Directory)
            {
                ReadOnlyFolderDelete(file);
            }
            else
            {
                // Remove all attributes first otherwise
                // this will fail against readonly files.
                fi.Attributes = FileAttributes.Normal;
                File.Delete(file);
            }

            // Send back to self to refresh.
            string deleteUrl =
                string.Format(
                    CultureInfo.InvariantCulture,
                    Strings.DeleteUrl,
                    UrlEncoding.Encode(_root));

            HttpContext.Current.Response.Redirect(deleteUrl, true);
        }
Exemple #2
0
        /// <summary>
        /// Refreshes the page.
        /// </summary>
        void Refresh()
        {
            string refresh =
                string.Format(
                    CultureInfo.InvariantCulture,
                    Strings.RRRefresh,
                    UrlEncoding.Encode(_root));

            Response.Redirect(refresh, true);
        }
Exemple #3
0
        /// <summary>
        /// Handles the Click event of the btnUpload control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            string upload =
                string.Format(
                    CultureInfo.InvariantCulture,
                    Strings.RRUpload,
                    UrlEncoding.Encode(_root));

            Response.Redirect(upload, true);
        }
Exemple #4
0
        /// <summary>
        /// Handles the Click event of the btnNewFolder control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void btnNewFolder_Click(object sender, EventArgs e)
        {
            string newFolder =
                string.Format(
                    CultureInfo.InvariantCulture,
                    Strings.RRNewFolder,
                    UrlEncoding.Encode(_root));

            Response.Redirect(newFolder, true);
        }
Exemple #5
0
        /// <summary>
        /// Renames the specified sender.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.CommandEventArgs"/> instance containing the event data.</param>
        void Rename(object sender, CommandEventArgs e)
        {
            string file      = e.CommandArgument.ToString();
            string renameUrl =
                string.Format(
                    CultureInfo.InvariantCulture,
                    Strings.RenameUrl,
                    UrlEncoding.Encode(_root),
                    UrlEncoding.Encode(file));

            HttpContext.Current.Response.Redirect(renameUrl, true);
        }
Exemple #6
0
        /// <summary>
        /// Creates data rows from each file and folder item.
        /// </summary>
        void DataRows()
        {
            TableRow  row;
            TableCell cell;
            FileInfo  fi;
            HyperLink hl;

            foreach (string item in _data)
            {
                // Will need some file info.
                fi = new FileInfo(item);

                // If the item attributes are Hidden or System, ignore.
                if ((fi.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden || (fi.Attributes & FileAttributes.System) == FileAttributes.System)
                {
                    continue;
                }

                // New row for each row found.
                row = new TableRow();

                if ((fi.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    // New cells for each item found.
                    cell = new TableCell();

                    // Get the folder image.
                    System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
                    img.ImageUrl   = _page.ClientScript.GetWebResourceUrl(typeof(WebFiler.Filer), Strings.PNG_FOLDER);
                    img.ImageAlign = ImageAlign.AbsBottom;
                    img.Style.Add(Strings.PaddingRight, Strings.FivePX);
                    cell.Controls.AddAt(0, img);

                    // Create the hyperlink.
                    hl             = new HyperLink();
                    hl.Text        = fi.Name;
                    hl.NavigateUrl =
                        string.Format(
                            CultureInfo.InvariantCulture,
                            Strings.RootNavigate,
                            _displayPage,
                            UrlEncoding.Encode(fi.FullName));

                    // Add the url.
                    cell.Controls.AddAt(1, hl);

                    // Add the composite cell to the row.
                    row.Cells.Add(cell);
                }
                else
                {
                    // Open the file to view as appropriate.
                    cell = new TableCell();

                    // Get the file type image.
                    System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
                    img.ImageUrl   = _page.ClientScript.GetWebResourceUrl(typeof(WebFiler.Filer), Strings.PNG_FILE);
                    img.ImageAlign = ImageAlign.AbsBottom;
                    img.Style.Add(Strings.PaddingRight, Strings.FivePX);
                    cell.Controls.AddAt(0, img);

                    // Create the hyperlink.
                    hl             = new HyperLink();
                    hl.Text        = fi.Name;
                    hl.NavigateUrl =
                        string.Format(
                            CultureInfo.InvariantCulture,
                            Strings.FileOpen,
                            UrlEncoding.Encode(fi.FullName));

                    cell.Controls.AddAt(1, hl);

                    // Add the composite cell to the row.
                    row.Cells.Add(cell);
                }

                // The size of the file.
                cell = new TableCell();
                cell.HorizontalAlign = HorizontalAlign.Right;
                // 20100601: Fix from Tony Hecht via CodeProject: original code failed when looking at compressed folders.
                cell.Text = ((fi.Attributes & FileAttributes.Directory) == FileAttributes.Directory) ? string.Empty : FormatFileSize(fi.Length);
                row.Cells.Add(cell);

                // The type of file: if a file has no extension display as 'unknown'.
                cell      = new TableCell();
                cell.Text =
                    (string.IsNullOrEmpty(fi.Extension))
                                                ? ((fi.Attributes == FileAttributes.Directory) ? Strings.Folder : Strings.Unknown)
                                                : fi.Extension.Replace(Strings.Period, string.Empty).ToLowerInvariant();
                row.Cells.Add(cell);

                // Is the file readonly?
                cell = new TableCell();
                cell.HorizontalAlign = HorizontalAlign.Center;
                cell.VerticalAlign   = VerticalAlign.Middle;
                cell.Text            = (fi.IsReadOnly) ? Strings.IsReadOnly : string.Empty;
                cell.ForeColor       = Color.MidnightBlue;
                cell.Font.Bold       = true;
                row.Cells.Add(cell);

                // Last access time.
                cell      = new TableCell();
                cell.Text = fi.LastAccessTime.ToString();
                row.Cells.Add(cell);

                // Last modified time.
                cell      = new TableCell();
                cell.Text = fi.LastWriteTime.ToString();
                row.Cells.Add(cell);

                // Action buttons.
                ImageButton btn;
                cell = new TableCell();

                // Rename.
                btn                 = new ImageButton();
                btn.ImageUrl        = _page.ClientScript.GetWebResourceUrl(typeof(WebFiler.Filer), Strings.PNG_RENAME);
                btn.ToolTip         = Strings.Rename;
                btn.Command        += new CommandEventHandler(Rename);
                btn.CommandArgument = fi.FullName;
                btn.Style.Add(Strings.PaddingRight, Strings.ThreePX);
                cell.Controls.AddAt(0, btn);

                // Delete.
                btn                 = new ImageButton();
                btn.ImageUrl        = _page.ClientScript.GetWebResourceUrl(typeof(WebFiler.Filer), Strings.PNG_DELETE);
                btn.ToolTip         = Strings.Delete;
                btn.Command        += new CommandEventHandler(Delete);
                btn.CommandArgument = fi.FullName;
                string deleteMsg =
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Strings.DeleteMessage,
                        fi.Name);
                ConfirmButton(btn, deleteMsg);
                cell.Controls.AddAt(1, btn);
                row.Cells.Add(cell);

                // Add the row to the table.
                _table.Rows.Add(row);
            }
        }
Exemple #7
0
        /// <summary>
        /// If below the root give a way to return.
        /// </summary>
        void RootRow()
        {
            // The root from the config.
            string primary = Configuration._root;

            // If it doesn't match where we are now then create a new row.
            if (primary != _root)
            {
                // Create the row.
                TableRow  row = new TableRow();
                TableCell cell;

                // Cell to hold the image and hyperlink.
                cell = new TableCell();

                // Get the folder image.
                System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
                img.ImageUrl   = _page.ClientScript.GetWebResourceUrl(typeof(WebFiler.Filer), Strings.PNG_FOLDER_UP);
                img.ImageAlign = ImageAlign.AbsBottom;
                img.Style.Add(Strings.PaddingRight, Strings.FivePX);
                cell.Controls.AddAt(0, img);

                // Get the parent directory.
                DirectoryInfo di     = new DirectoryInfo(_root);
                string        parent = di.Parent.FullName;

                // Add the url.
                // Create the hyperlink.
                HyperLink hl = new HyperLink();
                hl.Text        = Strings.FolderUpText;
                hl.NavigateUrl =
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Strings.RootNavigate,
                        _displayPage,
                        UrlEncoding.Encode(parent));

                cell.Controls.AddAt(1, hl);

                // Add the composite cell to the row.
                row.Cells.Add(cell);

                // Add dummy cells.
                cell = new TableCell();
                row.Cells.Add(cell);
                cell = new TableCell();
                row.Cells.Add(cell);
                cell = new TableCell();
                row.Cells.Add(cell);
                cell = new TableCell();
                row.Cells.Add(cell);
                cell = new TableCell();
                row.Cells.Add(cell);
                cell = new TableCell();
                row.Cells.Add(cell);

                // And add the row to the table.
                _table.Rows.AddAt(1, row);

                // Show the home button.
                ((Button)_page.FindControl("btnHome")).Visible = true;
            }
        }