Пример #1
0
        //****************************************************************
        //
        // The UpdateBtn_Click event handler on this Page is used to either
        // create or update an document.  It  uses the Nairc.KPWPortal.DocumentDB()
        // data component to encapsulate all data functionality.
        //
        //****************************************************************
        protected void UpdateBtn_Click(Object sender, EventArgs e)
        {
            // Only Update if Input Data is Valid
            if (Page.IsValid == true)
            {
                IDesktopModulesFacade facade = new DesktopModulesFacade();

                PortalDocument doc = new PortalDocument();
                doc.ModuleID=moduleId;
                doc.ItemID =itemId;
                doc.CreatedByUser =Context.User.Identity.Name;
                doc.FileFriendlyName =NameField.Text;
                doc.FileNameUrl =PathField.Text;
                doc.Category=CategoryField.Text;

                // 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
                    doc.Content =content;
                    doc.ContentSize =length;
                    doc.ContentType =contentType;
                    facade.UpdateDocument(doc);
                }
                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;
                    }
                    doc.Content = new byte[0];
                    doc.ContentSize = 0;
                    doc.ContentType = "";
                    facade.UpdateDocument(doc);
                }

                // Redirect back to the portal home page
                Response.Redirect((String) ViewState["UrlReferrer"]);
            }
        }
 public void UpdateDocumentTest()
 {
     //void UpdateDocument(int moduleId, int itemId, String userName, String name, String url, String category,
     //                byte[] content, int size, String contentType)
     DesktopModulesFacade facade = new DesktopModulesFacade();
     PortalDocument doc=new PortalDocument();
     doc.ModuleID = 0;
     doc.ItemID = 0;
     doc.CreatedByUser = "******";
     doc.FileFriendlyName = "n";
     doc.FileNameUrl = "url";
     doc.Category = "c";
     doc.Content = new byte[] {};
     doc.ContentSize = 0;
     doc.ContentType = "ct";
     facade.UpdateDocument(doc);
 }
        public void UpdateDocument(PortalDocument doc)
        {
            // TODO: add access security here..
            // TODO: add argument validation here..

            // Run within the context of a database transaction.
            // The Decorator Design Pattern.
            using (TransactionDecorator transaction = new TransactionDecorator())
            {
                documentDAO.UpdateDocument(doc.ModuleID, doc.ItemID, doc.CreatedByUser, doc.FileFriendlyName,
                                           doc.FileNameUrl, doc.Category,
                                           doc.Content, doc.ContentSize.Value, doc.ContentType);
                transaction.Complete();
            }
        }