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;
        }
        /// <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 + ";", "");
                        }
                    }
                }
            }
        }
        /// <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;
            }
        }
        /// <summary>
        /// This uploads a file which generates a GUID name, uses original image extension as save type. 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks></remarks>
        protected void cmdUpload_Click(System.Object sender, System.EventArgs e)
        {
            lblMessage.Text = string.Empty;
            try {
                // if no file is selected exit
                if (fuFile.PostedFile.FileName == string.Empty) {
                    return;
                }

                // Maximum attachment filesize = 5MB
                if (fuFile.PostedFile.InputStream.Length > (/*objConfig.MaxAttachmentSize*/5000 * 1024)) {
                    lblMessage.Text = Localization.GetString("MaxFileSize", this.LocalResourceFile) /*+ objConfig.MaxAttachmentSize.ToString()*/ + "5 MB";
                    return;
                }

                string FileName = System.IO.Path.GetFileName(fuFile.PostedFile.FileName);

                //Get destination folder as mappath
                string ParentFolderName = PortalSettings.HomeDirectoryMapPath;
                //ParentFolderName += BaseFolder;
                ParentFolderName = ParentFolderName.Replace("/", "\\");
                if (ParentFolderName.EndsWith("\\") == false)
                    ParentFolderName += "\\";

                string strExtension = System.IO.Path.GetExtension(fuFile.PostedFile.FileName).Replace(".", "");
                if (_fileFilter != string.Empty /*& Strings.InStr("," + _fileFilter.ToLower(), "," + strExtension.ToLower()) == 0*/) {
                    // trying to upload a file not allowed for current filter
                    lblMessage.Text = string.Format(Localization.GetString("UploadError", this.LocalResourceFile), _fileFilter, strExtension);
                }

                if (lblMessage.Text == string.Empty) {
                    //ParentFolderName = "C:\\inetpub\\wwwroot\\DNN6\\Portals\\0\\";
                    string destFileName = Guid.NewGuid().ToString().Replace("-", "") + "." + strExtension;
                    lblMessage.Text = FileSystemUtils.UploadFile(ParentFolderName, fuFile.PostedFile, false);

                    if (lblMessage.Text != string.Empty)
                        return;

                    //Rename the file using the GUID model
                    //FileSystemUtils.MoveFile(ParentFolderName + FileName, ParentFolderName + destFileName, PortalSettings);

                    destFileName = FileName;

                    //Now get the FileID from DNN Filesystem
                    int myFileID = 0;
                    ArrayList fileList = Globals.GetFileList(PortalId, strExtension);//, false, ParentFolderName, false);
                    foreach (FileItem objFile in fileList) {
                        if (objFile.Text == destFileName) {
                            myFileID = Convert.ToInt32(objFile.Value);
                        }
                    }

                    if (myFileID > 0) {
                        //Now save the Attachment info
                        AttachmentInfo objAttach = new AttachmentInfo();
                        var _with1 = objAttach;
                        _with1.PostID = PostId;
                        _with1.UserID = UserId;
                        _with1.FileID = myFileID;
                        _with1.LocalFileName = FileName;
                        _with1.Inline = false;

                        AttachmentController cntAttachment = new AttachmentController();
                        cntAttachment.Update(objAttach);
                        BindFileList();
                    }
                }
            } catch (Exception exc) {
                //ProcessModuleLoadException(this, exc);
                Response.Write(exc);
            }
        }