예제 #1
0
        public static bool CreateHistory(SharedFile file, IFileSystem fileSystem, string virtualFilePath, string virtualHistoryPath)
        {
            bool historyCreated = false;

            //File.Move(Path.Combine(sourceFilePath, Path.GetFileName(this.serverFileName)), Path.Combine(historyFolderPath, Path.GetFileName(this.serverFileName)));
            fileSystem.MoveFile(
                VirtualPathUtility.Combine(virtualFilePath, file.ServerFileName),
                VirtualPathUtility.Combine(virtualHistoryPath, file.ServerFileName),
                true);

            historyCreated = SharedFile.AddHistory(
                file.ItemGuid,
                file.ModuleGuid,
                file.UserGuid,
                file.ItemId,
                file.ModuleId,
                file.FriendlyName,
                file.OriginalFileName,
                file.ServerFileName,
                file.SizeInKB,
                file.UploadDate,
                file.UploadUserId);

            return historyCreated;
        }
예제 #2
0
        public bool Delete()
        {
            bool result = false;

            if (itemID == -1)
            {
                return(result);
            }

            SharedFile sharedFile = new SharedFile(moduleID, itemID);

            DBSharedFiles.DeleteHistoryByItemID(itemID);

            // this just deletes the entry from the db
            result = DBSharedFiles.DeleteSharedFile(itemID);

            if (result)
            {
                ContentChangedEventArgs e = new ContentChangedEventArgs();
                e.IsDeleted = true;
                OnContentChanged(e);
            }

            return(result);
        }
예제 #3
0
        public static DataTable GetFoldersAndFiles(int moduleId, int parentId)
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("ID", typeof(string));
            dt.Columns.Add("filename", typeof(string));
            dt.Columns.Add("OriginalFileName", typeof(string));
            dt.Columns.Add("Description", typeof(string));
            dt.Columns.Add("size", typeof(int));
            dt.Columns.Add("type", typeof(string));
            dt.Columns.Add("DownloadCount", typeof(string));
            dt.Columns.Add("modified", typeof(DateTime));
            dt.Columns.Add("username", typeof(string));

            DataRow dr;

            using (IDataReader reader = GetSharedFolders(moduleId, parentId))
            {
                while (reader.Read())
                {
                    dr                     = dt.NewRow();
                    dr["ID"]               = reader["FolderID"].ToString() + "~folder";
                    dr["filename"]         = reader["FolderName"];
                    dr["OriginalFileName"] = string.Empty;
                    dr["Description"]      = string.Empty;
                    dr["size"]             = reader["SizeInKB"].ToString();
                    dr["type"]             = "0";
                    dr["DownloadCount"]    = string.Empty;
                    dt.Rows.Add(dr);
                }
            }

            using (IDataReader reader = SharedFile.GetSharedFiles(moduleId, parentId))
            {
                while (reader.Read())
                {
                    dr                     = dt.NewRow();
                    dr["ID"]               = reader["ItemID"].ToString() + "~file";
                    dr["filename"]         = reader["FriendlyName"];
                    dr["OriginalFileName"] = reader["OriginalFileName"];
                    dr["Description"]      = reader["Description"];
                    dr["size"]             = reader["SizeInKB"].ToString();
                    dr["type"]             = "1";
                    dr["modified"]         = Convert.ToDateTime(reader["UploadDate"]);
                    dr["username"]         = reader["UserName"].ToString();
                    dr["DownloadCount"]    = reader["DownloadCount"].ToString();
                    dt.Rows.Add(dr);
                }
            }


            dt.AcceptChanges();

            return(dt);
        }
예제 #4
0
        public static FoldersAndFiles GetFoldersAndFilesModel(int moduleId, int parentId)
        {
            FoldersAndFiles foldersAndFiles = new FoldersAndFiles();

            using (IDataReader reader = GetSharedFolders(moduleId, parentId))
            {
                while (reader.Read())
                {
                    Folder newFolder = new Folder
                    {
                        ID         = Convert.ToInt32(reader["FolderID"]),
                        ModuleID   = Convert.ToInt32(reader["ModuleID"]),
                        Name       = reader["FolderName"].ToString(),
                        ParentID   = Convert.ToInt32(reader["ParentID"]),
                        ModuleGuid = new Guid(reader["ModuleGuid"].ToString()),
                        FolderGuid = new Guid(reader["FolderGuid"].ToString()),
                        ParentGuid = new Guid(reader["ParentGuid"].ToString()),
                        ViewRoles  = reader["ViewRoles"].ToString()
                    };

                    foldersAndFiles.Folders.Add(newFolder);
                }
            }

            using (IDataReader reader = SharedFile.GetSharedFiles(moduleId, parentId))
            {
                while (reader.Read())
                {
                    File newFile = new File
                    {
                        ID               = Convert.ToInt32(reader["ItemID"]),
                        ModuleID         = Convert.ToInt32(reader["ModuleID"]),
                        UploadUserID     = Convert.ToInt32(reader["UploadUserID"]),
                        Name             = reader["FriendlyName"].ToString(),
                        OriginalFileName = reader["OriginalFileName"].ToString(),
                        ServerFileName   = reader["ServerFileName"].ToString(),
                        SizeInKB         = Convert.ToInt32(reader["SizeInKB"]),
                        UploadDate       = Convert.ToDateTime(reader["UploadDate"]),
                        FolderID         = Convert.ToInt32(reader["FolderID"]),
                        ItemGuid         = new Guid(reader["ItemGuid"].ToString()),
                        ModuleGuid       = new Guid(reader["ModuleGuid"].ToString()),
                        UserGuid         = new Guid(reader["UserGuid"].ToString()),
                        FolderGuid       = new Guid(reader["FolderGuid"].ToString()),
                        Description      = reader["Description"].ToString(),
                        DownloadCount    = Convert.ToInt32(reader["DownloadCount"]),
                        ViewRoles        = reader["ViewRoles"].ToString()
                    };

                    foldersAndFiles.Files.Add(newFile);
                }
            }

            return(foldersAndFiles);
        }
예제 #5
0
        public static bool RestoreHistoryFile(
            int historyId, 
            IFileSystem fileSystem,
            string virtualSourcePath, 
            string virtualHistoryPath)
        {
            bool historyRestored = false;

            if (string.IsNullOrEmpty(virtualSourcePath)) { return historyRestored; }
            if (string.IsNullOrEmpty(virtualHistoryPath)) { return historyRestored; }
            if (fileSystem == null) { return historyRestored; }

            int itemId = 0;
            int moduleId = 0;
            string historyFriendlyName = string.Empty;
            string historyOriginalName = string.Empty;
            string historyServerName = string.Empty;
            DateTime historyUploadDate = DateTime.Now;
            int historyUploadUserID = 0;
            int historyFileSize = 0;

            using (IDataReader reader = SharedFile.GetHistoryFileAsIDataReader(historyId))
            {
                if (reader.Read())
                {
                    itemId = Convert.ToInt32(reader["ItemID"]);
                    moduleId = Convert.ToInt32(reader["ModuleID"]);
                    historyFriendlyName = reader["FriendlyName"].ToString();
                    historyOriginalName = reader["OriginalFileName"].ToString();
                    historyServerName = reader["ServerFileName"].ToString();
                    historyFileSize = Convert.ToInt32(reader["SizeInKB"]);
                    historyUploadUserID = Convert.ToInt32(reader["UploadUserID"]);
                    historyUploadDate = DateTime.Parse(reader["UploadDate"].ToString());

                }
            }

            SharedFile sharedFile = new SharedFile(moduleId, itemId);
            CreateHistory(sharedFile, fileSystem, virtualSourcePath, virtualHistoryPath);

            //File.Move(Path.Combine(historyPath, Path.GetFileName(historyServerName)), Path.Combine(sourcePath, Path.GetFileName(historyServerName)));
            fileSystem.MoveFile(
                VirtualPathUtility.Combine(virtualHistoryPath, historyServerName),
                VirtualPathUtility.Combine(virtualSourcePath, historyServerName),
                true);

            sharedFile.ServerFileName = historyServerName;
            sharedFile.OriginalFileName = historyOriginalName;
            sharedFile.FriendlyName = historyFriendlyName;
            sharedFile.SizeInKB = historyFileSize;
            sharedFile.UploadDate = historyUploadDate;
            sharedFile.UploadUserId = historyUploadUserID;
            historyRestored = sharedFile.Save();
            SharedFile.DeleteHistory(historyId);

            fileSystem.DeleteFile(VirtualPathUtility.Combine(virtualHistoryPath, historyServerName));

            return historyRestored;
        }
예제 #6
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());
        }
예제 #7
0
        private void PopulateFileControls()
        {
            Title = SiteUtils.FormatPageTitle(siteSettings, SharedFileResources.SharedFilesEditLabel);
            heading.Text = SharedFileResources.SharedFilesEditLabel;

            SharedFile file = new SharedFile(this.moduleId, this.itemId);
            if((file.ItemId > 0)&&(file.ModuleId == this.moduleId))
            {
                this.pnlNotFound.Visible = false;
                this.pnlFolder.Visible = false;
                this.pnlFile.Visible = true;

                using (IDataReader reader = SharedFileFolder.GetSharedModuleFolders(file.ModuleId))
                {
                    this.ddFolders.DataSource = reader;
                    this.ddFolders.DataBind();
                }
                this.ddFolders.Items.Insert(0,new ListItem("Root","-1"));
                this.ddFolders.SelectedValue = file.FolderId.ToInvariantString();

                hdnCurrentFolderId.Value = file.FolderId.ToInvariantString();

                if (timeZone != null)
                {
                    this.lblUploadDate.Text = file.UploadDate.ToLocalTime(timeZone).ToString();
                }
                else
                {
                    this.lblUploadDate.Text = file.UploadDate.AddHours(timeOffset).ToString();
                }

                SiteUser uploadUser = new SiteUser(siteSettings, file.UploadUserId);
                this.lblUploadBy.Text = uploadUser.Name;
                this.lblFileSize.Text = file.SizeInKB.ToString();
                this.txtFriendlyName.Text = file.FriendlyName;
                edDescription.Text = file.Description;

                if (config.EnableVersioning)
                {
                    using (IDataReader reader = file.GetHistory())
                    {
                        grdHistory.DataSource = reader;
                        grdHistory.DataBind();
                    }
                }

            }
            else
            {
                pnlNotFound.Visible = true;
                pnlFolder.Visible = false;
                pnlFile.Visible = false;
            }
        }
예제 #8
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);
        }
예제 #9
0
        private void btnUpdateFile_Click(object sender, EventArgs e)
        {
            SiteUser siteUser = SiteUtils.GetCurrentSiteUser();
            if (siteUser == null) return;

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

            if((file.ItemId > 0)&&(file.ModuleId == this.moduleId))
            {
                file.FriendlyName = this.txtFriendlyName.Text;
                file.Description = edDescription.Text;
                file.FolderId = int.Parse(this.ddFolders.SelectedValue);
                if (file.FolderId > -1)
                {
                    SharedFileFolder folder = new SharedFileFolder(this.moduleId,file.FolderId);
                    file.FolderGuid = folder.FolderGuid;
                }
                if (file.ModuleGuid == Guid.Empty)
                {
                    Module m = new Module(moduleId);
                    file.ModuleGuid = m.ModuleGuid;

                }

                file.UploadUserId = siteUser.UserId;
                // really last mod date
                file.UploadDate = DateTime.UtcNow;

                file.Save();

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

            WebUtils.SetupRedirect(this, SiteUtils.GetCurrentPageUrl());
        }
예제 #10
0
        public bool Delete()
        {
            bool result = false;

            if (itemID == -1) { return result; }
            SharedFile sharedFile = new SharedFile(moduleID, itemID);

            DBSharedFiles.DeleteHistoryByItemID(itemID);
            // this just deletes the entry from the db
            result =  DBSharedFiles.DeleteSharedFile(itemID);

            if (result)
            {
                ContentChangedEventArgs e = new ContentChangedEventArgs();
                e.IsDeleted = true;
                OnContentChanged(e);
            }

            return result;
        }
예제 #11
0
        public void ProcessRequest(HttpContext context)
        {
            base.Initialize(context);

            if (!UserCanEditModule(ModuleId, SharedFile.FeatureGuid))
            {
                log.Info("User has no edit permission so returning 404");
                Response.StatusCode = 404;
                return;
            }

            if (CurrentSite == null)
            {
                log.Info("CurrentSite is null so returning 404");
                Response.StatusCode = 404;
                return;
            }

            if (CurrentUser == null)
            {
                log.Info("CurrentUser is null so returning 404");
                Response.StatusCode = 404;
                return;
            }

            if (FileSystem == null)
            {
                log.Info("FileSystem is null so returning 404");
                Response.StatusCode = 404;
                return;
            }

            if (Request.Files.Count == 0)
            {
                log.Info("Posted File Count is zero so returning 404");
                Response.StatusCode = 404;
                return;
            }

            if (Request.Files.Count > SharedFilesConfiguration.MaxFilesToUploadAtOnce)
            {
                log.Info("Posted File Count is greater than allowed amount so returning 404");
                Response.StatusCode = 404;
                return;
            }

            module = GetModule(ModuleId, SharedFile.FeatureGuid);

            if (module == null)
            {
                log.Info("Module is null so returning 404");
                Response.StatusCode = 404;
                return;
            }

            itemId = WebUtils.ParseInt32FromQueryString("ItemID", itemId);
            currentFolderId = WebUtils.ParseInt32FromQueryString("frmData", currentFolderId);

            virtualSourcePath = "~/Data/Sites/" + CurrentSite.SiteId.ToInvariantString() + "/SharedFiles/";
            virtualHistoryPath = "~/Data/Sites/" + CurrentSite.SiteId.ToInvariantString() + "/SharedFiles/History/";

            Hashtable moduleSettings = ModuleSettings.GetModuleSettings(ModuleId);
            config = new SharedFilesConfiguration(moduleSettings);

            context.Response.ContentType = "text/plain";//"application/json";
            var r = new System.Collections.Generic.List<UploadFilesResult>();
            JavaScriptSerializer js = new JavaScriptSerializer();

            if (!FileSystem.FolderExists(virtualSourcePath))
            {
                FileSystem.CreateFolder(virtualSourcePath);
            }

            for (int f = 0; f < Request.Files.Count; f++)
            {
                HttpPostedFile file = Request.Files[f];

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

                SharedFile sharedFile;
                if ((itemId > -1) && (Request.Files.Count == 1))
                {
                    // updating an existing file
                    sharedFile = new SharedFile(ModuleId, itemId);

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

                    }
                }
                else
                {   // new file
                    sharedFile = new SharedFile();
                }
                sharedFile.ModuleId = ModuleId;
                sharedFile.ModuleGuid = module.ModuleGuid;
                sharedFile.OriginalFileName = fileName;
                sharedFile.FriendlyName = fileName;
                sharedFile.SizeInKB = (file.ContentLength / 1024);
                sharedFile.FolderId = currentFolderId;
                if (currentFolderId > -1)
                {
                    SharedFileFolder folder = new SharedFileFolder(ModuleId, currentFolderId);
                    sharedFile.FolderGuid = folder.FolderGuid;
                }
                sharedFile.UploadUserId = CurrentUser.UserId;
                sharedFile.UserGuid = CurrentUser.UserGuid;
                sharedFile.UploadDate = DateTime.UtcNow;

                sharedFile.ContentChanged += new ContentChangedEventHandler(sharedFile_ContentChanged);

                //file.SaveAs(Server.MapPath("~/Files/" + fileName));
                if (sharedFile.Save())
                {
                    string destPath = VirtualPathUtility.Combine(virtualSourcePath, sharedFile.ServerFileName);

                    using (Stream s = file.InputStream)
                    {
                        FileSystem.SaveFile(destPath, s, IOHelper.GetMimeType(Path.GetExtension(sharedFile.FriendlyName).ToLower()), true);
                    }

                }

                r.Add(new UploadFilesResult()
                {
                    //Thumbnail_url = savedFileName,
                    Name = fileName,
                    Length = file.ContentLength,
                    Type = file.ContentType
                });

            }

            CurrentPage.UpdateLastModifiedTime();
            CacheHelper.ClearModuleCache(ModuleId);
            SiteUtils.QueueIndexing();

            var uploadedFiles = new
            {
                files = r.ToArray()
            };
            var jsonObj = js.Serialize(uploadedFiles);
            context.Response.Write(jsonObj.ToString());
        }
        private static void IndexItem(SharedFile sharedFile)
        {
            if (WebConfigSettings.DisableSearchIndex) { return; }

            SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings();

            if (
                (sharedFile == null)
                || (siteSettings == null)
                )
            {
                return;
            }

            Guid sharedFilesFeatureGuid = new Guid("dc873d76-5bf2-4ac5-bff7-434a87a3fc8e");
            ModuleDefinition sharedFilesFeature = new ModuleDefinition(sharedFilesFeatureGuid);

            Module module = new Module(sharedFile.ModuleId);

            // get list of pages where this module is published
            List<PageModule> pageModules
                = PageModule.GetPageModulesByModule(sharedFile.ModuleId);

            foreach (PageModule pageModule in pageModules)
            {
                PageSettings pageSettings
                    = new PageSettings(
                    siteSettings.SiteId,
                    pageModule.PageId);

                //don't index pending/unpublished pages
                if (pageSettings.IsPending) { continue; }

                mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem();
                indexItem.SiteId = siteSettings.SiteId;
                indexItem.PageId = pageSettings.PageId;
                indexItem.PageName = pageSettings.PageName;
                indexItem.ViewRoles = pageSettings.AuthorizedRoles;
                indexItem.ModuleViewRoles = module.ViewRoles;
                indexItem.FeatureId = sharedFilesFeatureGuid.ToString();
                indexItem.FeatureName = sharedFilesFeature.FeatureName;
                indexItem.FeatureResourceFile = sharedFilesFeature.ResourceFile;
                indexItem.CreatedUtc = sharedFile.UploadDate;
                indexItem.LastModUtc = sharedFile.UploadDate;

                indexItem.ItemId = sharedFile.ItemId;
                indexItem.ModuleId = sharedFile.ModuleId;
                indexItem.ModuleTitle = module.ModuleTitle;
                indexItem.Title = sharedFile.FriendlyName.Replace("_", " ").Replace("-", " ").Replace(".", " ") ;
                indexItem.Content = sharedFile.Description;
                indexItem.PublishBeginDate = pageModule.PublishBeginDate;
                indexItem.PublishEndDate = pageModule.PublishEndDate;
                // make the search results a download link
                indexItem.ViewPage = "SharedFiles/Download.aspx?pageid=" + indexItem.PageId.ToInvariantString()
                    + "&fileid=" + indexItem.ItemId.ToInvariantString()
                    + "&mid=" + indexItem.ModuleId.ToInvariantString();
                indexItem.UseQueryStringParams = false;

                mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem);
            }

            if (debugLog) log.Debug("Indexed "  + sharedFile.FriendlyName);
        }
예제 #13
0
        public static void DeleteAllFiles(SharedFileFolder folder, IFileSystem fileSystem, string fileVirtualBasePath, SharedFilesConfiguration config)
        {
            // method implemented by Jean-Michel 2008-07-31

            // TODO: implement check whether versioning is enabled before calling this method
            // if we are keeping versions we should not delete the files

            if (folder == null) { return; }
            if (fileSystem == null) { return; }
            if (string.IsNullOrEmpty(fileVirtualBasePath)) { return; }
            if (folder.FolderId == -1) { return; }

            ArrayList folders = new ArrayList();
            ArrayList files = new ArrayList();
            using (IDataReader reader = SharedFile.GetSharedFiles(folder.ModuleId, folder.FolderId))
            {
                while (reader.Read())
                {
                    files.Add(Convert.ToInt32(reader["ItemID"]));
                }
            }

            using (IDataReader reader = SharedFileFolder.GetSharedFolders(folder.ModuleId, folder.FolderId))
            {
                while (reader.Read())
                {
                    folders.Add(Convert.ToInt32(reader["FolderID"]));
                }
            }

            foreach (int id in files)
            {
                SharedFile sharedFile = new SharedFile(folder.ModuleId, id);
                sharedFile.Delete();

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

                }
            }

            foreach (int id in folders)
            {
                SharedFileFolder subFolder = new SharedFileFolder(folder.ModuleId, id);

                DeleteAllFiles(subFolder, fileSystem, fileVirtualBasePath, config);

                SharedFileFolder.DeleteSharedFileFolder(id);
            }
        }
예제 #14
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);

            }
        }
예제 #15
0
        protected void dgFile_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            SiteUser siteUser = SiteUtils.GetCurrentSiteUser();
            if (siteUser == null) return;

            try
            {
                GridView grid = (GridView)sender;
                TextBox txtEditName = (TextBox)grid.Rows[e.RowIndex].Cells[1].FindControl("txtEditName");
                if (txtEditName.Text.Trim().Length < 1)
                    return;

                string keys = grid.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.FolderName = Path.GetFileName(txtEditName.Text);
                    folder.Save();

                }

                if (type == "file")
                {
                    int fileID = int.Parse(args[0]);
                    SharedFile sharedFile = new SharedFile(this.ModuleId, fileID);
                    sharedFile.ContentChanged += new ContentChangedEventHandler(sharedFile_ContentChanged);
                    sharedFile.FriendlyName = Path.GetFileName(txtEditName.Text);
                    sharedFile.UploadUserId = siteUser.UserId;
                    sharedFile.UploadDate = DateTime.UtcNow; //lastModDate
                    sharedFile.Save();

                }

                dgFile.EditIndex = -1;
                BindData();

            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message;
            }
            upFiles.Update();
        }
예제 #16
0
        protected void dgFile_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "ItemClicked")
            {

                string keys = e.CommandArgument.ToString();
                char[] separator = { '~' };
                string[] args = keys.Split(separator);
                string type = args[1];
                dgFile.EditIndex = -1;

                if (type == "folder")
                {
                    CurrentFolderId = int.Parse(args[0]);
                    BindData();
                    upFiles.Update();
                    return;

                }

                // this isn't used since we changed to a link to download.aspx
                if (type == "file")
                {
                    int fileID = int.Parse(args[0]);
                    SharedFile sharedFile = new SharedFile(this.ModuleId, fileID);

                    sharedFile.ContentChanged += new ContentChangedEventHandler(sharedFile_ContentChanged);

                    string virtualPath = "~/Data/Sites/" + this.SiteId.ToInvariantString()
                        + "/SharedFiles/" + sharedFile.ServerFileName;

                    string fileType = Path.GetExtension(sharedFile.OriginalFileName).Replace(".", string.Empty);
                    string mimeType = SiteUtils.GetMimeType(fileType);
                    Page.Response.ContentType = mimeType;

                    if (SiteUtils.IsNonAttacmentFileType(fileType))
                    {
                        //this will display the pdf right in the browser
                        Page.Response.AddHeader("Content-Disposition", "filename=\"" + HttpUtility.UrlEncode(sharedFile.FriendlyName.Replace(" ", string.Empty), Encoding.UTF8) + "\"");
                    }
                    else
                    {
                        // other files just use file save dialog
                        Page.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + HttpUtility.UrlEncode(sharedFile.FriendlyName.Replace(" ", string.Empty), Encoding.UTF8) + "\"");
                    }

                    Page.Response.Buffer = false;
                    Page.Response.BufferOutput = false;
                    //Page.Response.TransmitFile(downloadPath);
                    using (System.IO.Stream stream = fileSystem.GetAsStream(virtualPath))
                    {
                        stream.CopyTo(Page.Response.OutputStream);
                    }
                    try
                    {
                        Page.Response.End();
                    }
                    catch (System.Threading.ThreadAbortException) { }
                }

            }
        }
예제 #17
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            // as long as javascript is available this code should never execute
            // because the standard file input ir replaced by javascript and the file upload happens
            // at the service url /SharedFiles/upload.ashx
            // this is fallback implementation

            if (!fileSystem.FolderExists(fileVirtualBasePath))
            {
                fileSystem.CreateFolder(fileVirtualBasePath);
            }

            SiteUser siteUser = SiteUtils.GetCurrentSiteUser();

            if (siteUser == null) { WebUtils.SetupRedirect(this, Request.RawUrl); return; }

            if (uploader.HasFile)
            {
                SharedFile sharedFile = new SharedFile();

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

                sharedFile.ModuleId = ModuleId;
                sharedFile.ModuleGuid = ModuleConfiguration.ModuleGuid;
                sharedFile.OriginalFileName = fileName;
                sharedFile.FriendlyName = fileName;
                //sharedFile.SizeInKB = (int)(file.ContentLength / 1024);
                sharedFile.SizeInKB = (int)(uploader.FileContent.Length / 1024);
                sharedFile.FolderId = CurrentFolderId;
                if (CurrentFolderId > -1)
                {
                    SharedFileFolder folder = new SharedFileFolder(ModuleId, CurrentFolderId);
                    sharedFile.FolderGuid = folder.FolderGuid;
                }
                sharedFile.UploadUserId = siteUser.UserId;
                sharedFile.UserGuid = siteUser.UserGuid;

                sharedFile.ContentChanged += new ContentChangedEventHandler(sharedFile_ContentChanged);

                if (sharedFile.Save())
                {
                    string destPath = VirtualPathUtility.Combine(fileVirtualBasePath, sharedFile.ServerFileName);

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

                }
            }

            WebUtils.SetupRedirect(this, Request.RawUrl);
        }
        private void CreateFile(Module module, SharedFileFolder folder, SiteUser siteUser, XmlNode fileNode)
        {
            SharedFile sharedFile = new SharedFile();

            sharedFile.ModuleId = module.ModuleId;
            sharedFile.ModuleGuid = module.ModuleGuid;
            if (folder != null)
            {
                sharedFile.FolderId = folder.FolderId;
                sharedFile.FolderGuid = folder.FolderGuid;
            }

            if (siteUser != null)
            {
                sharedFile.UploadUserId = siteUser.UserId;
                sharedFile.UserGuid = siteUser.UserGuid;
            }

            XmlAttributeCollection fileAttributes = fileNode.Attributes;

            if (fileAttributes["originalFileName"] != null)
            {
                sharedFile.OriginalFileName = fileAttributes["originalFileName"].Value;
            }

            if (fileAttributes["friendlyName"] != null)
            {
                sharedFile.FriendlyName = fileAttributes["friendlyName"].Value;
            }

            if (fileAttributes["serverFileName"] != null)
            {
                sharedFile.ServerFileName = fileAttributes["serverFileName"].Value;
            }

            if (fileAttributes["sortOrder"] != null)
            {
                int size = 0;
                if (int.TryParse(fileAttributes["sortOrder"].Value, out size))
                {
                    sharedFile.SizeInKB = size;
                }
            }

            sharedFile.Save();
        }