Example #1
0
    /// <summary>
    /// Set up the view.
    /// </summary>
    void SetupView()
    {
        // If the folder is bogus...
        if (!Directory.Exists(_root))
        {
            Label label = new Label();
            label.Text =
                string.Format(
                    CultureInfo.InvariantCulture,
                    Resource.FolderNotFound,
                    _root);
            phDisplay.Controls.Add(label);
            return;
        }

        Folder folder = AccessManager.GetFolderKey(_root);

        ProfileCommon profile = HttpContext.Current.Profile as ProfileCommon;

        if (folder != null)
        {
            if (!SecurityHelper.CanUserView(HttpContext.Current.User.Identity.Name, folder.Id))
            {
                Label label = new Label();
                label.Text =
                    string.Format(
                        CultureInfo.InvariantCulture,
                        "Access Denied",
                        _root);
                phDisplay.Controls.Add(label);
                btnNewFile.Visible = btnNewFolder.Visible = btnUpload.Visible = false;
                return;
            }
        }

        // Get a new table of files and folders.
        Table table = new TableEx(this, _root).Create();

        // Display the table.
        if (table != null)
        {
            phDisplay.Controls.Add(table);
        }
        else
        {
            // Table wasn't created.
            Label label = new Label();
            label.Text = Resource.CantCreateTable;
            phDisplay.Controls.Add(label);
        }

        // Finally, if a file link was clicked, open it.
        OpenFile();
    }
Example #2
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)
            {
                // 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   = Resource.PNG_FOLDER;
                img.ImageAlign = ImageAlign.AbsBottom;
                img.Style.Add(Resource.PaddingRight, Resource.FivePX);
                cell.Controls.AddAt(0, img);

                // Create the hyperlink.
                hl             = new HyperLink();
                hl.Text        = fi.Name;
                hl.NavigateUrl =
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resource.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   = Resource.PNG_FILE;
                img.ImageAlign = ImageAlign.AbsBottom;
                img.Style.Add(Resource.PaddingRight, Resource.FivePX);
                cell.Controls.AddAt(0, img);

                // Create the hyperlink.
                hl             = new HyperLink();
                hl.Text        = fi.Name;
                hl.NavigateUrl =
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resource.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) ? Resource.Folder : Resource.Unknown)
                        : fi.Extension.Replace(Resource.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) ? Resource.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        = Resource.PNG_RENAME;
            btn.ToolTip         = Resource.Rename;
            btn.Command        += new CommandEventHandler(Rename);
            btn.CommandArgument = fi.FullName;
            btn.Style.Add(Resource.PaddingRight, Resource.ThreePX);
            cell.Controls.AddAt(0, btn);

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

            // Add the row to the table.
            if (fi.Attributes == FileAttributes.Directory)
            {
                Folder folder = AccessManager.GetFolderKey(fi.FullName);

                ProfileCommon profile = HttpContext.Current.Profile as ProfileCommon;

                // If the folder exists on the local disk, but not in the database, then ...
                // todo figure out how to handle directories which are on the local disk
                // but not in the database Folder table.
                if (folder == null)
                {
                    //Directory.Delete(fi.FullName, true);
                    continue;
                }

                //if (SecurityHelper.CanUserView(HttpContext.Current.User.Identity.Name, folder.Id))
                //{
                _table.Rows.Add(row);
                //}
            }
            else
            {
                _table.Rows.Add(row);
            }
        }
    }