/// <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 = DotNetNuke.Common.Utilities.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);
            }
        }
 /// <summary>
 /// Adds an AttachmentInfo object
 /// </summary>
 /// <param name="objAttachment"></param>
 /// <remarks></remarks>
 public void Update(AttachmentInfo objAttachment)
 {
     DataProvider pro = new DotNetNuke.Modules.uDebate.Data.DataProvider();
     pro.Attachment_Update(objAttachment);
 }
        /// <summary>
        /// Hydrates the AttachmentInfo object
        /// </summary>
        /// <param name="dr"></param>
        /// <returns></returns>
        /// <remarks>
        /// </remarks>
        /// <history>
        /// 	[skeel]	12/22/2008	Created
        /// </history>
        private AttachmentInfo FillAttachmentInfo(IDataReader dr)
        {
            AttachmentInfo objAttachment = new AttachmentInfo();
            try
            {
                objAttachment.AttachmentID = Convert.ToInt32(dr["AttachmentID"]);
            }
            catch
            {
            }
            try {
                objAttachment.FileID = Convert.ToInt32(dr["FileID"]);
            } catch {
            }
            try {
                objAttachment.PostID = Convert.ToInt32(dr["PostID"]);
            } catch {
            }
            try {
                objAttachment.UserID = Convert.ToInt32(dr["UserID"]);
            } catch {
            }
            try {
                objAttachment.LocalFileName = Convert.ToString(dr["LocalFileName"]);
            } catch {
            }
            try {
                objAttachment.FileName = Convert.ToString(dr["FileName"]);
            } catch {
            }
            try {
                objAttachment.Extension = Convert.ToString(dr["Extension"]);
            } catch {
            }
            try {
                objAttachment.Size = Convert.ToInt32(dr["Size"]);
            } catch {
            }
            try {
                objAttachment.Inline = Convert.ToBoolean(dr["Inline"]);
            } catch {
            }
            try {
                objAttachment.Width = Convert.ToInt32(dr["Width"]);
            } catch {
            }
            try {
                objAttachment.Height = Convert.ToInt32(dr["Height"]);
            } catch {
            }

            return objAttachment;
        }
예제 #4
0
 public void Attachment_Update(AttachmentInfo objAttachment)
 {
     SqlHelper.ExecuteNonQuery(_connectionString,  "uDebate_Attachment_Update", objAttachment.AttachmentID, objAttachment.FileID, objAttachment.PostID, objAttachment.UserID, objAttachment.LocalFileName, objAttachment.Inline);
 }