Esempio n. 1
0
        private void btnDeleteFile_Click(object sender, EventArgs e)
        {
            SharedFile sharedFile = new SharedFile(moduleId, itemId);

            if (sharedFile.ModuleId != moduleId)
            {
                SiteUtils.RedirectToAccessDeniedPage(this);

                return;
            }

            sharedFile.ContentChanged += new ContentChangedEventHandler(sharedFile_ContentChanged);

            if (config.EnableVersioning)
            {
                SharedFilesHelper.CreateHistory(sharedFile, fileSystem, virtualSourcePath, virtualHistoryPath);
            }

            sharedFile.Delete();
            CurrentPage.UpdateLastModifiedTime();
            CacheHelper.ClearModuleCache(moduleId);
            SiteUtils.QueueIndexing();

            if (hdnReturnUrl.Value.Length > 0)
            {
                WebUtils.SetupRedirect(this, hdnReturnUrl.Value);

                return;
            }

            WebUtils.SetupRedirect(this, SiteUtils.GetCurrentPageUrl());
        }
Esempio n. 2
0
        private void DeleteItem(GridViewRow e)
        {
            string keys = dgFile.DataKeys[e.RowIndex].Value.ToString();

            char[]   separator = { '~' };
            string[] args      = keys.Split(separator);
            string   type      = args[1];

            if (type == "folder")
            {
                int folderID            = int.Parse(args[0]);
                SharedFileFolder folder = new SharedFileFolder(this.ModuleId, folderID);
                //folder.DeleteAllFiles(this.filePath);
                SharedFilesHelper.DeleteAllFiles(folder, fileSystem, fileVirtualBasePath, config);
                SharedFileFolder.DeleteSharedFileFolder(folderID);

                //TODO: file content changed event so re-index
            }

            if (type == "file")
            {
                int        fileID     = int.Parse(args[0]);
                SharedFile sharedFile = new SharedFile(this.ModuleId, fileID);

                if (!config.EnableVersioning)
                {
                    fileSystem.DeleteFile(VirtualPathUtility.Combine(fileVirtualBasePath, sharedFile.ServerFileName));
                }

                sharedFile.Delete();

                sharedFile.ContentChanged += new ContentChangedEventHandler(SharedFile_ContentChanged);
            }
        }
Esempio n. 3
0
        void grdHistory_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int archiveID = Convert.ToInt32(e.CommandArgument);

            switch (e.CommandName)
            {
            case "restore":
                //SharedFile.RestoreHistoryFile(archiveID, this.upLoadPath, this.historyPath);
                SharedFilesHelper.RestoreHistoryFile(archiveID, fileSystem, virtualSourcePath, virtualHistoryPath);
                WebUtils.SetupRedirect(this, Request.RawUrl);
                break;

            case "deletehx":
                SharedFilesHelper.DeleteHistoryFile(archiveID, fileSystem, virtualHistoryPath);
                SharedFile.DeleteHistory(archiveID);

                WebUtils.SetupRedirect(this, Request.RawUrl);
                break;

            case "download":

                SharedFileHistory historyFile = SharedFile.GetHistoryFile(archiveID);
                if (historyFile != null)
                {
                    string fileType = Path.GetExtension(historyFile.FriendlyName).Replace(".", string.Empty);
                    if (string.Equals(fileType, "pdf", StringComparison.InvariantCultureIgnoreCase))
                    {
                        //this will display the pdf right in the browser
                        Page.Response.AddHeader("Content-Disposition", "filename=" + historyFile.FriendlyName);
                    }
                    else
                    {
                        // other files just use file save dialog
                        Page.Response.AddHeader("Content-Disposition", "attachment; filename=" + historyFile.FriendlyName);
                    }

                    //Page.Response.AddHeader("Content-Length", documentFile.DocumentImage.LongLength.ToString());

                    Page.Response.ContentType  = "application/" + fileType;
                    Page.Response.Buffer       = false;
                    Page.Response.BufferOutput = false;
                    //Response.TransmitFile(historyPath + historyFile.ServerFileName);
                    //Response.End();

                    using (System.IO.Stream stream = fileSystem.GetAsStream(virtualHistoryPath + historyFile.ServerFileName))
                    {
                        stream.CopyTo(Page.Response.OutputStream);
                    }
                    try
                    {
                        Page.Response.End();
                    }
                    catch (System.Threading.ThreadAbortException) { }
                }

                break;
            }
        }
Esempio n. 4
0
        private void btnUpload_Click(object sender, EventArgs e)
        {
            if (uploader.HasFile)
            {
                SiteUser siteUser = SiteUtils.GetCurrentSiteUser();
                if (siteUser == null)
                {
                    return;
                }

                SharedFile sharedFile = new SharedFile(this.moduleId, this.itemId);
                sharedFile.ContentChanged += new ContentChangedEventHandler(sharedFile_ContentChanged);

                if (config.EnableVersioning)
                {
                    bool historyCreated = SharedFilesHelper.CreateHistory(sharedFile, fileSystem, virtualSourcePath, virtualHistoryPath);
                    if (historyCreated)
                    {
                        sharedFile.ServerFileName = System.Guid.NewGuid().ToString() + ".config";
                    }
                }


                sharedFile.ModuleId = this.moduleId;
                if (sharedFile.ModuleGuid == Guid.Empty)
                {
                    Module m = GetModule(moduleId, SharedFile.FeatureGuid);
                    sharedFile.ModuleGuid = m.ModuleGuid;
                }

                string fileName = Path.GetFileName(uploader.FileName);

                sharedFile.OriginalFileName = fileName;
                sharedFile.FriendlyName     = fileName;
                sharedFile.SizeInKB         = (int)(uploader.FileBytes.Length / 1024);
                sharedFile.UploadUserId     = siteUser.UserId;
                sharedFile.UploadDate       = DateTime.UtcNow;

                if (sharedFile.Save())
                {
                    string destPath = virtualSourcePath + sharedFile.ServerFileName;

                    using (Stream s = uploader.FileContent)
                    {
                        //fileSystem.SaveFile(destPath, file1.FileContent, file1.ContentType, true);
                        fileSystem.SaveFile(destPath, s, IOHelper.GetMimeType(Path.GetExtension(sharedFile.FriendlyName).ToLower()), true);
                    }
                }



                CurrentPage.UpdateLastModifiedTime();
                CacheHelper.ClearModuleCache(moduleId);
                SiteUtils.QueueIndexing();
            }

            WebUtils.SetupRedirect(this, Request.RawUrl);
        }
Esempio n. 5
0
        private void PopulateFolderControls()
        {
            Title        = SiteUtils.FormatPageTitle(siteSettings, SharedFileResources.SharedFilesEditFolderLabel);
            heading.Text = SharedFileResources.SharedFilesEditFolderLabel;
            SharedFileFolder folder = new SharedFileFolder(this.moduleId, this.itemId);

            if ((folder.FolderId > 0) && (folder.ModuleId == this.moduleId))
            {
                this.pnlNotFound.Visible = false;
                this.pnlFile.Visible     = false;
                this.pnlFolder.Visible   = true;

                this.txtFolderName.Text = folder.FolderName;

                List <SharedFileFolder> allFolders = SharedFileFolder.GetSharedModuleFolderList(folder.ModuleId);

                this.ddFolderList.DataSource = allFolders;
                this.ddFolderList.DataBind();

                this.ddFolderList.Items.Insert(0, new ListItem("Root", "-1"));
                this.ddFolderList.SelectedValue = folder.ParentId.ToString();

                // prevent a folder from being its own parent
                ListItem item = this.ddFolderList.Items.FindByText(folder.FolderName);
                if (item != null)
                {
                    this.ddFolderList.Items.Remove(item);
                }


                //// prevent a children folder from being parent
                //// build list
                List <int> toRemove = new List <int>();
                foreach (ListItem fldItem in this.ddFolderList.Items)
                {
                    //SharedFileFolder currentFolder = new SharedFileFolder(this.moduleId, Convert.ToInt32(fldItem.Value));
                    SharedFileFolder currentFolder = SharedFilesHelper.GetFolderFromListById(Convert.ToInt32(fldItem.Value), allFolders);
                    if (currentFolder != null)
                    {
                        if (SharedFilesHelper.GetAllParentsFolderIds(currentFolder, allFolders).Contains(folder.FolderId))
                        {
                            toRemove.Add(currentFolder.FolderId);
                        }
                    }
                }
                // remove list
                foreach (int itemToRemove in toRemove)
                {
                    this.ddFolderList.Items.Remove(this.ddFolderList.Items.FindByValue(itemToRemove.ToInvariantString()));
                }
            }
            else
            {
                this.pnlNotFound.Visible = true;
                this.pnlFolder.Visible   = false;
                this.pnlFile.Visible     = false;
            }
        }
Esempio n. 6
0
        private void BindData()
        {
            if (CurrentFolderId > -1)
            {
                SharedFileFolder folder = new SharedFileFolder(ModuleId, CurrentFolderId);

                btnGoUp.Visible         = true;
                rptFoldersLinks.Visible = true;

                if (displaySettings.ShowClickableFolderPathCrumbs)
                {
                    lblCurrentDirectory.Visible = false;

                    // by Thomas N
                    List <SharedFileFolder> allFolders = SharedFileFolder.GetSharedModuleFolderList(folder.ModuleId);
                    rptFoldersLinks.DataSource = SharedFilesHelper.GetAllParentsFolder(folder, allFolders);

                    IEnumerable <SharedFileFolder> fullPathList = SharedFilesHelper.GetAllParentsFolder(folder, allFolders).Concat(Enumerable.Repeat(folder, 1));
                    rptFoldersLinks.DataSource = fullPathList;
                    rptFoldersLinks.DataBind();
                }
                else
                {
                    lblCurrentDirectory.Text = folder.FolderName;
                }
            }
            else
            {
                lblCurrentDirectory.Visible = false;
                btnGoUp.Visible             = false;
                rptFoldersLinks.Visible     = false;
            }

            DataView dv = new DataView(SharedFileFolder.GetFoldersAndFiles(ModuleId, CurrentFolderId));

            EnumerableRowCollection <DataRow> query =
                from row in dv.Table.AsEnumerable()
                where CheckRoles(row.Field <string>("ViewRoles"))
                select row;

            DataView view = query.AsDataView();

            view.Sort         = $"type ASC, filename {config.DefaultSort}";
            dgFile.DataSource = view;
            dgFile.DataBind();

            lblCounter.Text = $"{dgFile.Rows.Count.ToString()} {SharedFileResources.FileManagerObjectsLabel}";
        }
Esempio n. 7
0
        private void btnDeleteFolder_Click(object sender, EventArgs e)
        {
            SharedFileFolder folder = new SharedFileFolder(this.moduleId, this.itemId);

            if ((folder.FolderId > 0) && (folder.ModuleId == this.moduleId))
            {
                SharedFilesHelper.DeleteAllFiles(folder, fileSystem, virtualSourcePath, config);
                SharedFileFolder.DeleteSharedFileFolder(this.itemId);

                CacheHelper.ClearModuleCache(moduleId);
                if (hdnReturnUrl.Value.Length > 0)
                {
                    WebUtils.SetupRedirect(this, hdnReturnUrl.Value);
                    return;
                }
            }

            WebUtils.SetupRedirect(this, SiteUtils.GetCurrentPageUrl());
        }
        private void BindData()
        {
            if (CurrentFolderId > -1)
            {
                SharedFileFolder folder = new SharedFileFolder(this.ModuleId, CurrentFolderId);

                btnGoUp.Visible         = true;
                rptFoldersLinks.Visible = true;

                if (displaySettings.ShowClickableFolderPathCrumbs)
                {
                    lblCurrentDirectory.Visible = false;

                    // by Thomas N
                    List <SharedFileFolder> allFolders = SharedFileFolder.GetSharedModuleFolderList(folder.ModuleId);
                    rptFoldersLinks.DataSource = SharedFilesHelper.GetAllParentsFolder(folder, allFolders);
                    IEnumerable <SharedFileFolder> fullPathList = SharedFilesHelper.GetAllParentsFolder(folder, allFolders).Concat(Enumerable.Repeat(folder, 1));
                    rptFoldersLinks.DataSource = fullPathList;
                    rptFoldersLinks.DataBind();
                }
                else
                {
                    lblCurrentDirectory.Text = folder.FolderName;
                }
            }
            else
            {
                lblCurrentDirectory.Visible = false;
                btnGoUp.Visible             = false;
                rptFoldersLinks.Visible     = false;
            }

            DataView dv = new DataView(SharedFileFolder.GetFoldersAndFiles(ModuleId, CurrentFolderId));

            dv.Sort           = "type ASC, filename" + " " + config.DefaultSort;
            dgFile.DataSource = dv;
            dgFile.DataBind();
            lblCounter.Text = dgFile.Rows.Count.ToString() + " "
                              + SharedFileResources.FileManagerObjectsLabel;
        }