示例#1
0
    protected override void OnPreRender(EventArgs e)
    {
        string linkId = Request.QueryString["id"];

        if (linkId == null)
        {
            ErrorMessageLabel.Text = "Invalid link";
            return;
        }

        FileShareMain fm = new FileShareMain();

        try
        {
            FileShare fs = fm.GetLocalFilePath(linkId);
            if (fs != null)
            {
                Session["IsAuthorized"] = true;
                Session["linkId"]       = linkId;

                if (fs.IsDirectory)
                {
                    Hashtable            htFiles = new Hashtable();
                    System.IO.FileInfo[] files   = new System.IO.DirectoryInfo(fs.FilePath).GetFiles();
                    FileLinkPanel.Controls.Clear();
                    HtmlGenericControl ul = new HtmlGenericControl("ul");
                    FileLinkPanel.Controls.Add(ul);

                    foreach (System.IO.FileInfo fi in files)
                    {
                        HtmlGenericControl li  = new HtmlGenericControl("li");
                        HtmlAnchor         lnk = new HtmlAnchor();
                        lnk.InnerText = fi.Name;

                        string linkHashCode = SHA2Hash.GetSHA2Hash(SHA2Hash.HashBits.n256, HASH_SALT + fi.Name + HASH_SALT2);
                        lnk.HRef = "download/" + linkHashCode;

                        //Add record to hashtable
                        htFiles.Add(linkHashCode, fi.FullName);

                        li.Controls.Add(lnk);
                        ul.Controls.Add(li);
                    }
                    HttpRuntime.Cache.Insert("AvailableFileHashTable_" + linkId, htFiles, null, DateTime.Now.AddHours(1), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.NotRemovable, null);
                }
            }
        }
        catch (Exception ex)
        {
            ErrorMessageLabel.Text = ex.Message;
        }
        base.OnPreRender(e);
    }
示例#2
0
 protected void GenerateButton_click(object sender, EventArgs e)
 {
     if (FilePathTextBox.Text.Length > 0)
     {
         FileShareMain fm          = new FileShareMain();
         bool          isDirectory = !System.IO.Path.HasExtension(FilePathTextBox.Text); //CheckIfIsDir(FilePathTextBox.Text);
         try
         {
             if (!isDirectory && !(new System.IO.FileInfo(FilePathTextBox.Text).Exists))
             {
                 ErrorLabel.Text = "invalid path";
                 return;
             }
             string baseUrl = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/') + "/";
             string linkId  = fm.CreateLocalFileLink(FilePathTextBox.Text, isDirectory);
             urlTextBox.Text = baseUrl + "Download.aspx?id=" + linkId;
         }
         catch (Exception ex)
         {
             ErrorLabel.Text = ex.Message;
         }
     }
 }