コード例 #1
0
        /// <summary>
        /// The DeleteBtn_Click event handler on this Page is used to delete an
        /// a document. It uses the Rainbow.DocumentsDB()
        /// data component to encapsulate all data functionality.
        /// </summary>
        override protected void OnDelete(EventArgs e)
        {
            base.OnDelete(e);

            // Only attempt to delete the item if it is an existing item
            // (new items will have "ItemID" of 0)
            //TODO: Ask confim before delete
            if (ItemID != 0)
            {
                DocumentDB documents = new DocumentDB();
                documents.DeleteDocument(ItemID, Server.MapPath(PathField.Text));
            }
            this.RedirectBackToReferringPage();
        }
コード例 #2
0
        /// <summary>
        /// The Page_Load event handler on this Page is used to
        /// obtain obtain the contents of a document from the
        /// Documents table, construct an HTTP Response of the
        /// correct type for the document, and then stream the
        /// document contents to the response.  It uses the
        /// Rainbow.DocumentDB() data component to encapsulate
        /// the data access functionality.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Page_Load(object sender, System.EventArgs e)
        {
            if (ItemID != -1)
            {
                // Obtain Document Data from Documents table
                DocumentDB documents = new DocumentDB();

                // Change by [email protected]
                // Date: 7/2/2003
                WorkFlowVersion version = Request.QueryString["wversion"] == "Staging" ? WorkFlowVersion.Staging : WorkFlowVersion.Production;
                // End Change [email protected]

                // Change by [email protected]
                // Date: 7/2/2003
                // Original:
                // SqlDataReader dBContent = documents.GetDocumentContent(ItemID);
                SqlDataReader dBContent = documents.GetDocumentContent(ItemID, version);
                // End Change [email protected]

                try
                {
                    dBContent.Read();

                    // Serve up the file by name
                    // [email protected]. FIX: FileName does not exist
                    // Response.AppendHeader("content-disposition", "filename=" + (string)dBContent["FileName"]);
                    Response.AppendHeader("content-disposition", "filename=" + (string)dBContent["FileNameUrl"]);

                    // set the content type for the Response to that of the
                    // document to display.  For example. "application/msword"
                    // Change for translate extension-files to exact contentType
                    // Response.ContentType = (string) dBContent["ContentType"];
                    Response.ContentType = giveMeContentType((string)dBContent["ContentType"]);

                    // output the actual document contents to the response output stream
                    Response.OutputStream.Write((byte[])dBContent["Content"], 0, (int)dBContent["ContentSize"]);
                }
                finally
                {
                    dBContent.Close();                     //by Manu, fixed bug 807858
                }

                // end the response
                Response.End();
            }
        }
コード例 #3
0
        /// <summary>
        /// The Page_Load event on this Page is used to obtain the ModuleID
        /// and ItemID of the document to edit.
        /// It then uses the DocumentDB() data component
        /// to populate the page's edit controls with the document details.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Page_Load(object sender, System.EventArgs e)
        {
            // If the page is being requested the first time, determine if an
            // document itemID value is specified, and if so populate page
            // contents with the document details

            if (!Page.IsPostBack)
            {
                if (ModuleID > 0)
                {
                    PathToSave = ((SettingItem)moduleSettings["DocumentPath"]).FullPath;
                }

                if (ItemID > 0)
                {
                    // Obtain a single row of document information
                    DocumentDB    documents = new DocumentDB();
                    SqlDataReader dr        = documents.GetSingleDocument(ItemID, WorkFlowVersion.Staging);

                    try
                    {
                        // Load first row into Datareader
                        if (dr.Read())
                        {
                            NameField.Text     = (string)dr["FileFriendlyName"];
                            PathField.Text     = (string)dr["FileNameUrl"];
                            CategoryField.Text = (string)dr["Category"];
                            CreatedBy.Text     = (string)dr["CreatedByUser"];
                            CreatedDate.Text   = ((DateTime)dr["CreatedDate"]).ToShortDateString();
                            // 15/7/2004 added localization by Mario Endara [email protected]
                            if (CreatedBy.Text == "unknown")
                            {
                                CreatedBy.Text = Esperantus.Localize.GetString("UNKNOWN", "unknown");
                            }
                        }
                    }
                    finally
                    {
                        dr.Close();
                    }
                }
            }
        }
コード例 #4
0
        override protected void OnUpdate(EventArgs e)
        {
            base.OnUpdate(e);
            byte [] buffer = new byte[0];
            int     size   = 0;

            // Only Update if Input Data is Valid
            if (Page.IsValid)
            {
                // Create an instance of the Document DB component
                DocumentDB documents = new DocumentDB();

                // Determine whether a file was uploaded
                if (FileUpload.PostedFile.FileName != string.Empty)
                {
                    FileInfo fInfo = new FileInfo(FileUpload.PostedFile.FileName);
                    if (bool.Parse(moduleSettings["DOCUMENTS_DBSAVE"].ToString()))
                    {
                        System.IO.Stream stream = FileUpload.PostedFile.InputStream;
                        buffer = new byte[FileUpload.PostedFile.ContentLength];
                        size   = FileUpload.PostedFile.ContentLength;
                        try
                        {
                            stream.Read(buffer, 0, size);
                            PathField.Text = fInfo.Name;
                        }
                        finally
                        {
                            stream.Close();                             //by manu
                        }
                    }
                    else
                    {
                        PathToSave = ((SettingItem)moduleSettings["DocumentPath"]).FullPath;
                        // [email protected] (02/07/2004). Create the Directory if not exists.
                        if (!System.IO.Directory.Exists(Server.MapPath(PathToSave)))
                        {
                            System.IO.Directory.CreateDirectory(Server.MapPath(PathToSave));
                        }

                        string virtualPath  = Rainbow.Settings.Path.WebPathCombine(PathToSave, fInfo.Name);
                        string phyiscalPath = Server.MapPath(virtualPath);

                        while (System.IO.File.Exists(phyiscalPath))
                        {
                            // Calculate virtualPath of the newly uploaded file
                            virtualPath = Rainbow.Settings.Path.WebPathCombine(PathToSave, Guid.NewGuid().ToString() + fInfo.Extension);

                            // Calculate physical path of the newly uploaded file
                            phyiscalPath = Server.MapPath(virtualPath);
                        }

                        try
                        {
                            // Save file to uploads directory
                            FileUpload.PostedFile.SaveAs(phyiscalPath);

                            // Update PathFile with uploaded virtual file location
                            PathField.Text = virtualPath;
                        }
                        catch (Exception ex)
                        {
                            Message.Text = Esperantus.Localize.GetString("ERROR_FILE_NAME", "Invalid file name!<br>") + ex.Message;
                            return;
                        }
                    }
                }
                // Change for save contenType and document buffer
                // documents.UpdateDocument(ModuleID, ItemID, PortalSettings.CurrentUser.Identity.Email, NameField.Text, PathField.Text, CategoryField.Text, new byte[0], 0, string.Empty );
                string contentType = PathField.Text.Substring(PathField.Text.LastIndexOf(".") + 1).ToLower();
                documents.UpdateDocument(ModuleID, ItemID, PortalSettings.CurrentUser.Identity.Email, NameField.Text, PathField.Text, CategoryField.Text, buffer, size, contentType);

                this.RedirectBackToReferringPage();
            }
        }
コード例 #5
0
        /// <summary>
        /// The Page_Load event handler on this User Control is used to
        /// obtain a SqlDataReader of document information from the
        /// Documents table, and then databind the results to a DataGrid
        /// server control.  It uses the Rainbow.DocumentDB()
        /// data component to encapsulate all data functionality.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Page_Load(object sender, System.EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                string sortFieldOption     = Settings["DOCUMENTS_SORTBY_FIELD"].ToString();
                string sortDirectionOption = Settings["DOCUMENTS_SORTBY_DIRECTION"].ToString();
                if (sortFieldOption.Length > 0)
                {
                    if (Esperantus.Localize.GetString("DOCUMENTS_SORTBY_FIELD_LIST", "File Name;Created Date").IndexOf(sortFieldOption) > 0)
                    {
                        sortField = "CreatedDate";
                    }
                    else
                    {
                        sortField = "FileFriendlyName";
                    }

                    if (Esperantus.Localize.GetString("DOCUMENTS_SORTBY_DIRECTION_LIST", "Ascending;Descending").IndexOf(sortDirectionOption) > 0)
                    {
                        sortDirection = "DESC";
                    }
                    else
                    {
                        sortDirection = "ASC";
                    }
                }
                else
                {
                    sortField     = "FileFriendlyName";
                    sortDirection = "ASC";
                    if (sortField == "DueDate")
                    {
                        sortDirection = "DESC";
                    }
                }
                ViewState["SortField"]     = sortField;
                ViewState["SortDirection"] = sortDirection;
            }
            else
            {
                sortField     = (string)ViewState["SortField"];
                sortDirection = (string)ViewState["sortDirection"];
            }

            myDataView = new DataView();

            // Obtain Document Data from Documents table
            // and bind to the datalist control
            DocumentDB documents = new DocumentDB();

            // DataSet documentsData = documents.GetDocuments(ModuleID, Version);
            // myDataView = documentsData.Tables[0].DefaultView;
            setDataView(documents.GetDocuments(ModuleID, Version));

            if (!Page.IsPostBack)
            {
                myDataView.Sort = sortField + " " + sortDirection;
            }

            BindGrid();
        }