Exemplo n.º 1
0
    protected string GetViewArticleUrl(string id)
    {
        Article article = DocoManager.GetArticle(id);

        string root = Server.MapPath(Path.Combine("~/Doco/", System.Web.Configuration.WebConfigurationManager.AppSettings.Get(Resources.Resource.Root)));
        string path =
            string.Format(
                CultureInfo.InvariantCulture,
                Resource.NewObjectPath,
                root,
                article.Category.Id);

        if (!string.IsNullOrEmpty(article.FileName))
        {
            string url = string.Format(
                CultureInfo.InvariantCulture,
                Resource.DocoFilesLoc + Resource.FileOpen,
                UrlEncoding.Encode(Path.Combine(path, article.FileName)));
            return(url);
        }
        else
        {
            return(string.Empty);
        }
    }
Exemplo n.º 2
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,
                Resource.DeleteUrl,
                UrlEncoding.Encode(_root));

        HttpContext.Current.Response.Redirect(deleteUrl, true);
    }
Exemplo n.º 3
0
        public void EncodeStringWithSpaceSetting(string?strEncoded, string?strDecoded)
        {
            var settings = new UrlEncodingSettings();

            settings.EncodedSpaceChar = '+';
            Assert.AreEqual(strEncoded, UrlEncoding.Encode(strDecoded, settings));
        }
    protected void lnkFileName_Click(object sender, EventArgs e)
    {
        string documentId = Request["id"]; //check for id in URL

        if (!string.IsNullOrEmpty(documentId))
        {
            Article article = DocoManager.GetArticle(documentId);
            AuditManager.Audit(Page.User.Identity.Name, article.Id, AuditRecord.AuditAction.Viewed);
            article = DocoManager.GetArticle(documentId);
            SetTrafficLight(article);

            string navigateUrl =
                string.Format(
                    CultureInfo.InvariantCulture,
                    Resource.NewObjectPath,
                    "Files",
                    article.Category.Id);

            if (!string.IsNullOrEmpty(article.FileName))
            {
                navigateUrl = string.Format(
                    CultureInfo.InvariantCulture,
                    Resource.DocoFilesLoc + Resource.FileOpen,
                    UrlEncoding.Encode(Path.Combine(navigateUrl, article.FileName)));
                navigateUrl = navigateUrl.Insert(navigateUrl.IndexOf("&"), "&aid=" + article.Id);

                // go to that url
                Page.Response.Redirect(navigateUrl);
            }
        }
    }
Exemplo n.º 5
0
        public void ChangeBytePrefixCharEncode()
        {
            var settings = new UrlEncodingSettings();

            settings.EncodedBytePrefixChar = '+';
            Assert.AreEqual("Hi+2c+20there", UrlEncoding.Encode("Hi, there", settings));
            Assert.AreEqual("Hi+2c+20there+20Ed+2e", UrlEncoding.Encode("Hi, there Ed.", settings));
        }
Exemplo n.º 6
0
        public void ChangeBytePrefixCharToBackslashEncode()
        {
            var settings = new UrlEncodingSettings();

            settings.EncodedBytePrefixChar = '\\';
            Assert.AreEqual("Hi\\2c\\20there", UrlEncoding.Encode("Hi, there", settings));
            Assert.AreEqual("Hi\\2c\\20there\\20Ed\\2e", UrlEncoding.Encode("Hi, there Ed.", settings));
        }
Exemplo n.º 7
0
        public void ChangeEncoding()
        {
            var settings = new UrlEncodingSettings();

            settings.TextEncoding = Encoding.UTF32;
            Assert.AreEqual("Hi%2c%00%00%00%20%00%00%00there", UrlEncoding.Encode("Hi, there", settings));
            Assert.AreEqual("Hi%2c%00%00%00%20%00%00%00there%20%00%00%00Ed%2e%00%00%00", UrlEncoding.Encode("Hi, there Ed.", settings));
        }
Exemplo n.º 8
0
        public void OnlyEncodeSpaces()
        {
            var settings = new UrlEncodingSettings();

            settings.ShouldEncodeChar = ch => ch == ' ';
            Assert.AreEqual("Hi,%20there", UrlEncoding.Encode("Hi, there", settings));
            Assert.AreEqual("Hi,%20there%20Ed.", UrlEncoding.Encode("Hi, there Ed.", settings));
        }
Exemplo n.º 9
0
        public void OnlyEncodeSpaces()
        {
            UrlEncodingSettings settings = new UrlEncodingSettings();

            settings.ShouldEncodeChar = delegate(char ch) { return(ch == ' '); };
            Assert.AreEqual("Hi,%20there", UrlEncoding.Encode("Hi, there", settings));
            Assert.AreEqual("Hi,%20there%20Ed.", UrlEncoding.Encode("Hi, there Ed.", settings));
        }
Exemplo n.º 10
0
        public void EncodeStringWithSpaceCustomShouldEncode(string?strEncoded, string?strDecoded)
        {
            var settings = new UrlEncodingSettings
            {
                EncodedSpaceChar = '+',
                ShouldEncodeChar = ch => ch == 'e',
            };

            Assert.AreEqual(strEncoded, UrlEncoding.Encode(strDecoded, settings));
            Assert.AreEqual(strDecoded, UrlEncoding.Decode(strEncoded, settings));
        }
Exemplo n.º 11
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,
                Resource.RenameUrl,
                UrlEncoding.Encode(_root),
                UrlEncoding.Encode(file));

        HttpContext.Current.Response.Redirect(renameUrl, true);
    }
Exemplo n.º 12
0
        public void SettingsFromSettings()
        {
            var settings = new UrlEncodingSettings();

            settings.TextEncoding = Encoding.UTF32;

            var settingsNew = settings.Clone();

            settingsNew.EncodedBytePrefixChar = '+';

            Assert.AreEqual("Hi+2c+00+00+00+20+00+00+00there", UrlEncoding.Encode("Hi, there", settingsNew));
            Assert.AreEqual("Hi+2c+00+00+00+20+00+00+00there+20+00+00+00Ed+2e+00+00+00", UrlEncoding.Encode("Hi, there Ed.", settingsNew));
        }
Exemplo n.º 13
0
        public void SettingsClone()
        {
            var settings = new UrlEncodingSettings
            {
                EncodedBytePrefixChar = '!',
                EncodedSpaceChar      = '$',
                PreventDoubleEncoding = true,
                UppercaseHexDigits    = true,
                ShouldEncodeChar      = ch => ch == '@',
                TextEncoding          = Encoding.UTF32,
            };
            var settingsClone = settings.Clone();

            Assert.AreEqual(settings.EncodedBytePrefixChar, settingsClone.EncodedBytePrefixChar);
            Assert.AreEqual(settings.EncodedSpaceChar, settingsClone.EncodedSpaceChar);
            Assert.AreEqual(settings.PreventDoubleEncoding, settingsClone.PreventDoubleEncoding);
            Assert.AreEqual(settings.UppercaseHexDigits, settingsClone.UppercaseHexDigits);
            Assert.AreEqual(UrlEncoding.Encode("!@#$ 駉", settings), UrlEncoding.Encode("!@#$ 駉", settingsClone));
        }
Exemplo n.º 14
0
    /// <summary>
    /// Retrieves a URL friendly string that points to an article.
    /// </summary>
    /// <param name="name">The name of the article</param>
    /// <returns>A user friendly Url for the article</returns>
    protected string GetViewArticleUrl(string name)
    {
        // If it is an uploaded document, then view the document and set the acknowledged flag
        // to true (via audit).
        Article article = DocoManager.GetArticleByName(name, false);

        if (article.IsUpload)
        {
            if (!article.Acknowledged)
            {
                // todo Popup to say that this will be acknowledged.
                AuditManager.Audit(Page.User.Identity.Name, article.Id + article.Version.ToString(CultureInfo.InvariantCulture), AuditRecord.AuditAction.Acknowledged);
            }

            string root = Server.MapPath(System.IO.Path.Combine("../Doco/", System.Web.Configuration.WebConfigurationManager.AppSettings.Get(Resource.Root)));
            string path =
                string.Format(
                    CultureInfo.InvariantCulture,
                    Resource.NewObjectPath,
                    root,
                    article.Category.Id);

            if (!string.IsNullOrEmpty(article.FileName))
            {
                string url = string.Format(
                    CultureInfo.InvariantCulture,
                    Resource.DocoFilesLoc + Resource.FileOpen,
                    UrlEncoding.Encode(System.IO.Path.Combine(path, article.FileName)));
                return(url);
            }
            else
            {
                return(string.Empty);
            }
        }
        else
        {
            return(Navigation.Doco_ViewArticle(name, 0).GetClientUrl(this, true) + "&cMode=pub&id=" + article.Category.Id);
        }
    }
Exemplo n.º 15
0
 public void EncodeNullSettings()
 {
     Assert.Throws <ArgumentNullException>(() => UrlEncoding.Encode("test", null !));
 }
Exemplo n.º 16
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);
            }
        }
    }
Exemplo n.º 17
0
 public void EncodeString(string?strEncoded, string?strDecoded)
 {
     Assert.AreEqual(strEncoded, UrlEncoding.Encode(strDecoded));
 }
Exemplo n.º 18
0
    /// <summary>
    /// If below the root give a way to return.
    /// </summary>
    void RootRow()
    {
        // The root from the config.
        string primary = HttpContext.Current.Server.MapPath(WebConfigurationManager.AppSettings.Get(Resource.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   = Resource.PNG_FOLDER_UP;
            img.ImageAlign = ImageAlign.AbsBottom;
            img.Style.Add(Resource.PaddingRight, Resource.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        = Resource.FolderUpText;
            hl.NavigateUrl =
                string.Format(
                    CultureInfo.InvariantCulture,
                    Resource.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;
        }
    }
Exemplo n.º 19
0
 private static string?Encode(string?str, bool encode) =>
 encode?UrlEncoding.Encode(str, EncodingSettings) : str;