//******************************************************* // // 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 // ASPNetPortal.DocumentDB() data component to encapsulate // the data access functionality. // //******************************************************* private void Page_Load(object sender, System.EventArgs e) { if (Request.Params["DocumentId"] != null) { documentId = Int32.Parse(Request.Params["DocumentId"]); } if (documentId != -1) { // Obtain Document Data from Documents table ASPNetPortal.DocumentDB documents = new ASPNetPortal.DocumentDB(); IDataReader dBContent = documents.GetDocumentContent(documentId); dBContent.Read(); // Serve up the file by name Response.AppendHeader("content-disposition", "filename=" + (String)dBContent["filefriendlyname"]); // set the content type for the Response to that of the // document to display. For example. "application/msword" Response.ContentType = (String)dBContent["contenttype"]; // output the actual document contents to the response output stream Response.OutputStream.Write((byte[])dBContent["content"], 0, (int)dBContent["contentsize"]); // end the response Response.End(); } }
//******************************************************* // // 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 ASPNetPortal.DocumentDB() // data component to encapsulate all data functionality. // //******************************************************* private void Page_Load(object sender, System.EventArgs e) { // Obtain Document Data from Documents table // and bind to the datalist control ASPNetPortal.DocumentDB documents = new ASPNetPortal.DocumentDB(); myDataGrid.DataSource = documents.GetDocuments(ModuleId); myDataGrid.DataBind(); }
//**************************************************************** // // The DeleteBtn_Click event handler on this Page is used to delete an // a document. It uses the ASPNetPortal.DocumentsDB() // data component to encapsulate all data functionality. // //**************************************************************** private void DeleteBtn_Click(Object sender, EventArgs e) { // Only attempt to delete the item if it is an existing item // (new items will have "ItemId" of 0) if (itemId != 0) { ASPNetPortal.DocumentDB documents = new ASPNetPortal.DocumentDB(); documents.DeleteDocument(itemId); } // Redirect back to the portal home page Response.Redirect((String)ViewState["UrlReferrer"]); }
//**************************************************************** // // The UpdateBtn_Click event handler on this Page is used to either // create or update an document. It uses the ASPNetPortal.DocumentDB() // data component to encapsulate all data functionality. // //**************************************************************** private void UpdateBtn_Click(Object sender, EventArgs e) { // Only Update if Input Data is Valid if (Page.IsValid == true) { // Create an instance of the Document DB component ASPNetPortal.DocumentDB documents = new ASPNetPortal.DocumentDB(); // Determine whether a file was uploaded if ((storeInDatabase.Checked == true) && (FileUpload.PostedFile != null)) { // for web farm support int length = (int)FileUpload.PostedFile.InputStream.Length; String contentType = FileUpload.PostedFile.ContentType; byte[] content = new byte[length]; FileUpload.PostedFile.InputStream.Read(content, 0, length); // Update the document within the Documents table documents.UpdateDocument(moduleId, itemId, Context.User.Identity.Name, NameField.Text, PathField.Text, CategoryField.Text, content, length, contentType); } else { if ((Upload.Checked == true) && (FileUpload.PostedFile != null)) { // Calculate virtualPath of the newly uploaded file String virtualPath = "~/uploads/" + Path.GetFileName(FileUpload.PostedFile.FileName); // Calculate physical path of the newly uploaded file String phyiscalPath = Server.MapPath(virtualPath); // Save file to uploads directory FileUpload.PostedFile.SaveAs(phyiscalPath); // Update PathFile with uploaded virtual file location PathField.Text = virtualPath; } documents.UpdateDocument(moduleId, itemId, Context.User.Identity.Name, NameField.Text, PathField.Text, CategoryField.Text, new byte[0], 0, ""); } // Redirect back to the portal home page Response.Redirect((String)ViewState["UrlReferrer"]); } }
//**************************************************************** // // The Page_Load event on this Page is used to obtain the ModuleId // and ItemId of the document to edit. // // It then uses the ASPNetPortal.DocumentDB() data component // to populate the page's edit controls with the document details. // //**************************************************************** private void Page_Load(object sender, System.EventArgs e) { // Determine ModuleId of Announcements Portal Module moduleId = Int32.Parse(Request.Params["Mid"]); // Verify that the current user has access to edit this module if (PortalSecurity.HasEditPermissions(moduleId) == false) { Response.Redirect("~/Admin/EditAccessDenied.aspx"); } // Determine ItemId of Document to Update if (Request.Params["ItemId"] != null) { itemId = Int32.Parse(Request.Params["ItemId"]); } // 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 == false) { if (itemId != 0) { // Obtain a single row of document information ASPNetPortal.DocumentDB documents = new ASPNetPortal.DocumentDB(); IDataReader dr = documents.GetSingleDocument(itemId); // Load first row into Datareader 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(); dr.Close(); } // Store URL Referrer to return to portal ViewState["UrlReferrer"] = Request.UrlReferrer.ToString(); } }