Exemple #1
0
        /// <summary>
        /// Binds a list of files to a drop down list.
        /// </summary>
        /// <remarks></remarks>
        private void BindFileList()
        {
            lstAttachments.Items.Clear();

            AttachmentController  cntAttachment = new AttachmentController();
            List <AttachmentInfo> lstFiles      = null;

            if (PostId > 0)
            {
                lstFiles = cntAttachment.GetAllByPostID(PostId);
                //Check for "lost" uploads from previous uncompleted posts and add them to the list
                List <AttachmentInfo> lstTemp = cntAttachment.GetAllByUserID(UserId);
                if (lstTemp.Count > 0)
                {
                    lstFiles.AddRange(lstTemp);
                }
            }
            else
            {
                //Check for "lost" uploads from previous uncompleted posts and add them to the list
                lstFiles = cntAttachment.GetAllByUserID(UserId);
            }


            foreach (AttachmentInfo objFile in lstFiles)
            {
                ListItem lstItem = new ListItem();
                lstItem.Text  = objFile.LocalFileName;
                lstItem.Value = objFile.FileName;
                lstAttachments.Items.Add(lstItem);
                lstAttachmentIDs += objFile.AttachmentID.ToString() + ";";

                ViewState["attachment"] = objFile.AttachmentID;
            }
        }
        public string getAttachedFilesByPostId(string PostId)
        {
            string SQL = @"SELECT [ID],[UserTitle],[FileTitle],[FileSize],[FileType],[PostId]
                        FROM [uDebate_Forum_Post_Files] where PostId=" + PostId;

            string sHTML = string.Empty;

            AttachmentController  cntAttachment = new AttachmentController();
            List <AttachmentInfo> lstFiles      = null;

            if (Convert.ToInt32(PostId) > 0)
            {
                lstFiles = cntAttachment.GetAllByPostID(Convert.ToInt32(PostId));
            }

            if (lstFiles.Count > 0)
            {
                sHTML += "<table class='attachments' cellspacing='0' cellpadding='0' width='160px'>";
                sHTML += "<td style='border-top: 1px solid #FDFDFD; padding:5px 3px;width:24px;'> <img src='" + ATC.Tools.GetParam("RootURL") +
                         @"DesktopModules/uDebate/images/s_attachment.png' align=middle'> </td> ";
                foreach (AttachmentInfo objFile in lstFiles)
                {
                    string strlink     = Common.Globals.LinkClick("FileID=" + objFile.FileID, PortalSettings.ActiveTab.TabID, ModuleId, false, true);
                    string strFileName = objFile.LocalFileName;
                    sHTML += @" <td style='border-top: 1px solid #FDFDFD; padding: 5px 0;'><a href='" + strlink + "'>"
                             + strFileName.Substring(0, Math.Min(strFileName.Length, 15)).ToLower() + @"</a>&nbsp;</td>";
                }
                sHTML += "</table>";
            }
            return(sHTML);
        }
Exemple #3
0
        /// <summary>
        /// When the control is loaded, we want to make sure the cmdUpload is registered for postback because of the nature of the file upload control and security.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks></remarks>
        protected void Page_Load(object sender, System.EventArgs e)
        {
            //Localization (needed because of AJAX)
            cmdDelete.ToolTip = Localization.GetString("Delete", this.LocalResourceFile);
            cmdUpload.Text    = Localization.GetString("Upload", this.LocalResourceFile);
            //plUpload.Text = Localization.GetString("plUpload", this.LocalResourceFile) + ":";
            //plUpload.HelpText = Localization.GetString("plUpload.Help", this.LocalResourceFile);
            //plAttachments.Text = Localization.GetString("plAttachments", this.LocalResourceFile) + ":";
            //plAttachments.HelpText = Localization.GetString("plAttachments.Help", this.LocalResourceFile);

            // We can only delete files while not in use, look for Items to be deleted (PostID set to -2)
            if (Page.IsPostBack == false)
            {
                AttachmentController  cntAttachment  = new AttachmentController();
                List <AttachmentInfo> lstAttachments = cntAttachment.GetAllByPostID(-2);
                if (lstAttachments.Count > 0)
                {
                    foreach (AttachmentInfo objFile in lstAttachments)
                    {
                        DeleteItems += objFile.FileName + ";";
                    }
                }
            }
            else
            {
                //Delete any files set for deletion

                if (DeleteItems != string.Empty)
                {
                    string ParentFolderName = PortalSettings.HomeDirectoryMapPath;
                    ParentFolderName += BaseFolder;
                    ParentFolderName  = ParentFolderName.Replace("/", "\\");
                    if (ParentFolderName.EndsWith("\\") == false)
                    {
                        ParentFolderName += "\\";
                    }

                    char[]   splitter = { ';' };
                    string[] Array    = DeleteItems.Split(splitter);

                    foreach (string item in Array)
                    {
                        if (item != string.Empty)
                        {
                            DotNetNuke.Common.Utilities.FileSystemUtils.DeleteFile(ParentFolderName + item, PortalSettings, true);
                            // Remove the filename from DeleteItems.
                            // If it was not deleted, it will be picked up next time
                            DeleteItems = DeleteItems.Replace(item + ";", "");
                        }
                    }
                }
            }
        }