示例#1
0
        /// <summary>
        /// Upload Button Click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UploadButton_Click(object sender, EventArgs e)
        {
            try
            {
                bool   PPSet         = web.IsPassPhraseSet();
                string PassPhraseStr = null;
                if (PPSet && PassPhraseLabel.Visible)
                {
                    PassPhraseStr = PassPhraseText.Text.Trim();

                    if (PassPhraseStr.Length == 0)
                    {
                        Message.Text = GetString("IFOLDER.NOPASSPHRASE");
                        return;
                    }
                    // verify the entered pass-phrase
                    Status ObjValidate = web.ValidatePassPhrase(PassPhraseStr);
                    if (ObjValidate.statusCode != StatusCodes.Success)
                    {
                        Message.Text        = GetString("PASSPHRASE_INCORRECT");
                        PassPhraseText.Text = "";
                        return;
                    }
                }
                else if (PPSet && (EncryptionAlgorithm != null && EncryptionAlgorithm != String.Empty))
                {
                    string PassPhrase = Session["SessionPassPhrase"] as string;
                    // verify the entered pass-phrase
                    Status ObjValidate = web.ValidatePassPhrase(PassPhrase);
                    if (ObjValidate.statusCode != StatusCodes.Success)
                    {
                        Message.Text                 = GetString("PASSPHRASE_INCORRECT");
                        PassPhraseText.Text          = "";
                        Session["SessionPassPhrase"] = null;
                        Response.Redirect(String.Format("Browse.aspx?iFolder={0}&Message={1}", ifolderID, Message.Text));
                        return;
                    }
                }
                // Call WebServices API to get the matched folder list
                string         UploadFileName = null;
                bool           MatchFound     = false;
                string         ExistingFiles  = null;
                ArrayList      Uploadedfiles  = new ArrayList();
                HttpPostedFile filename       = null;
                if (!OverWriteCheckbox.Checked)
                {
                    foreach (string name in Request.Files)
                    {
                        filename = Request.Files[name];
                        Uploadedfiles.Add(WebUtility.GetFileName((filename).FileName.Trim()));
                    }
                    string[] Array = new string[Uploadedfiles.Count];
                    Uploadedfiles.CopyTo(Array);

                    iFolderEntrySet matchentries = web.GetMatchedEntries(ifolderID, entryID, Array);

                    if (matchentries.Total > 0)
                    {
                        //List of files to be Uploaded
                        foreach (string name in Request.Files)
                        {
                            filename       = Request.Files[name];
                            UploadFileName = WebUtility.GetFileName((filename).FileName.Trim());
                            if (UploadFileName.Length == 0)
                            {
                                continue;
                            }

                            //List of Matched Entries
                            foreach (iFolderEntry child in matchentries.Items)
                            {
                                if ((UploadFileName.ToLower()).Equals(child.Name.ToLower()))
                                {
                                    MatchFound = true;
                                    break;
                                }
                            }
                            if (false == MatchFound)
                            {
                                UploadFile(Request.Files[name], PassPhraseStr);
                            }
                            else
                            {
                                //reseting the flag for next Iteration
                                MatchFound = false;
                            }
                        }
                    }     /* End of IF (matchentries.Total > 0) */
                    else
                    {
                        //if OverWriteCheckbox is checked, but files to be upload doesn't match with the existing file
                        foreach (string name in Request.Files)
                        {
                            UploadFile(Request.Files[name], PassPhraseStr);
                        }
                    }
                }         /* End of IF  (!OverWriteCheckbox.Checked)  */
                else
                {
                    //if OverWriteCheckbox is unchecked.
                    foreach (string name in Request.Files)
                    {
                        UploadFile(Request.Files[name], PassPhraseStr);
                    }
                }

                Response.Redirect(String.Format("Browse.aspx?iFolder={0}&Entry={1}&Alg={2}", ifolderID, entryID, EncryptionAlgorithm));
            }
            catch (Exception ex)
            {
                if (!HandleException(ex))
                {
                    throw;
                }
            }
        }
示例#2
0
        /// <summary>
        /// Bind the Data to the Page.
        /// </summary>
        private void BindEntryData()
        {
            // query
            string pattern = Request.QueryString.Get("Pattern");

            // TODO: fix
            if ((pattern == null) || (pattern.Length == 0))
            {
                return;
            }

            // entries
            DataTable entryTable = new DataTable();

            entryTable.Columns.Add("ID");
            entryTable.Columns.Add("iFolderID");
            entryTable.Columns.Add("Link");
            entryTable.Columns.Add("Image");
            entryTable.Columns.Add("Name");
            entryTable.Columns.Add("Size");
            entryTable.Columns.Add("LastModified");
            entryTable.Columns.Add("IsDirectory", typeof(bool));

            try
            {
                string escPattern = Regex.Escape(pattern).Replace("\\*", ".*").Replace("\\?", ".");
                // entries
                iFolderEntrySet entries = web.GetEntriesByName(ifolderID, entryID, SearchOperation.Contains,
                                                               escPattern, EntryPagging.Index, EntryPagging.PageSize);

                // pagging
                EntryPagging.Total = entries.Total;
                EntryPagging.Count = entries.Items.Length;

                string name;
                string path;

                foreach (iFolderEntry child in entries.Items)
                {
                    DataRow row = entryTable.NewRow();

                    // selected name
                    name = Regex.Replace(child.Name, String.Format("({0})", escPattern),
                                         "<span class='highlight'>${1}</span>", RegexOptions.IgnoreCase);

                    // remove the iFolder name from the path
                    path = child.Path.Substring(child.Path.IndexOf('/'));

                    // remove the file name from the path
                    path = path.Substring(0, path.LastIndexOf('/') + 1);

                    row["ID"]        = child.ID;
                    row["iFolderID"] = child.iFolderID;
                    row["Name"]      = path + name;

                    if (child.IsDirectory)
                    {
                        row["Link"] = String.Format("Browse.aspx?iFolder={0}&Entry={1}",
                                                    ifolderID, child.ID);
                        row["Image"] = "folder.png";
                        row["Size"]  = "";
                    }
                    else
                    {
                        row["Link"] = String.Format("Download.ashx?iFolder={0}&Entry={1}",
                                                    ifolderID, child.ID);
                        row["Image"] = "text-x-generic.png";
                        row["Size"]  = WebUtility.FormatSize(child.Size, rm);
                    }

                    row["LastModified"] = WebUtility.FormatDate(child.LastModified, rm);
                    row["IsDirectory"]  = child.IsDirectory;

                    entryTable.Rows.Add(row);
                }
            }
            catch (SoapException ex)
            {
                if (!HandleException(ex))
                {
                    throw;
                }
            }

            // bind
            EntryData.DataKeyField = "ID";
            EntryData.DataSource   = entryTable;
            EntryData.DataBind();
        }
示例#3
0
        /// <summary>
        /// Bind the Data to the Page.
        /// </summary>
        private void BindEntryData()
        {
            // entries
            DataTable entryTable = new DataTable();

            entryTable.Columns.Add("ID");
            entryTable.Columns.Add("iFolderID");
            entryTable.Columns.Add("Link");
            entryTable.Columns.Add("Image");
            entryTable.Columns.Add("Name");
            entryTable.Columns.Add("Size");
            entryTable.Columns.Add("LastModified");
            entryTable.Columns.Add("IsDirectory", typeof(bool));

            try
            {
                //Location of ifolder.
                string ifolderLocation = web.GetiFolderLocation(ifolderID);

                UriBuilder remoteurl = new UriBuilder(ifolderLocation);
                remoteurl.Path = (new Uri(web.Url)).PathAndQuery;
                web.Url        = remoteurl.Uri.ToString();

                // entries
                iFolderEntrySet entries = web.GetEntries(ifolderID, entryID, EntryPagging.Index, EntryPagging.PageSize);

                // pagging
                EntryPagging.Total = entries.Total;
                EntryPagging.Count = entries.Items.Length;

                foreach (iFolderEntry child in entries.Items)
                {
                    int    Namelenght = 70;
                    string shortName  = null;
                    shortName = child.Name;
                    if (child.Name.Length > Namelenght)
                    {
                        shortName = web.GetShortenedName(child.Name, Namelenght);
                    }

                    DataRow row = entryTable.NewRow();

                    row["ID"]        = child.ID;
                    row["iFolderID"] = child.iFolderID;
                    row["Name"]      = shortName;

                    if (child.IsDirectory)
                    {
                        row["Link"] = String.Format("Browse.aspx?iFolder={0}&Entry={1}",
                                                    ifolderID, child.ID);
                        row["Image"] = "folder.png";
                        row["Size"]  = WebUtility.FormatSize(child.Size, rm);
                    }
                    else
                    {
                        row["Link"] = String.Format("Download.ashx?iFolder={0}&Entry={1}",
                                                    ifolderID, child.ID);
                        row["Image"] = "text-x-generic.png";
                        row["Size"]  = WebUtility.FormatSize(child.Size, rm);
                    }

                    row["LastModified"] = WebUtility.FormatDate(child.LastModified, rm);
                    row["IsDirectory"]  = child.IsDirectory;

                    entryTable.Rows.Add(row);
                }
            }
            catch (SoapException ex)
            {
                if (!HandleException(ex))
                {
                    throw;
                }
            }

            // bind
            EntryData.DataKeyField = "ID";
            EntryData.DataSource   = entryTable;
            EntryData.DataBind();
        }