ERP system Upload Document information download (18)

Source: Internet
Author: User
Tags windows download

Common Methods for downloading:

 <summary>///download Documents///</summary>//<param name= "TableName" > Enquiry Form </param>  <param name= "column" > Query column </param>//<param name= "condition" > Query conditions </param>/// <returns>byte[]</returns> public static byte[] Getdowndocumet (string tablename,string column,string con           dition) {Long datalen = 0;           System.Data.SqlClient.SqlDataReader reader= sqlcomm.getdatareaderbycondition (TableName, column, condition);           byte[] data = null; try {while (reader. Read ()) {//Read the length of the data Datalen = reader.                   GetBytes (0, 0, data, 0, 1);                   Allocate the ease zone data = new Byte[datalen]; Read Data Datalen = reader.               GetBytes (0, 0, data, 0, (int) datalen); } reader.               Close ();           return data; } catch (EXception ex) {return null; }          }

Download:

Get the document binary stream:

Filecontent = Comm.getdowndocumet ("Biocrmcorrelationdocument", "Content", "documentid=" + ID);

Download the specific steps:

protected void Lbtndown_click (object sender, EventArgs e)        {            //create pop-up Windows download form            Response.AddHeader (" Content-disposition "," Attachment;filename= "+httputility.urlencode (This.lbName.Text));            Writes a binary array to the HTTP output stream            response.binarywrite (filecontent);            Want current client buffer output            Response.Flush ();            Stop execution            Response.End ();        }

Modify the background code:

 Static byte[] filecontent = null; private void Pageinfoband () {if (request.querystring["ID"]! = null) {string id = request.querystring["id"].                ToString ();                BIOCRMCORRELATIONDOCUMENTBLL DBLL = new BIOCRMCORRELATIONDOCUMENTBLL ();                Documentinfoview dv = new Documentinfoview ();                Dv=dbll.getdocumentviewbyid (ID); This.txtsubJect.Text = dv.                Subject; This.txtRemark.Text = dv.                Remark; This.lbType.Text = dv.                Type; This.txtCustomerID.Text = dv.                Customerid.tostring (); This.ddlLevel.SelectedItem.Text = dv.                Documentlevel; this.cbDelete.Checked = dv.                Deletestate; This.lbExtendName.Text = dv.                Exetendname; This.lbName.Text = dv.                Name;                Filecontent = Comm.getdowndocumet ("Biocrmcorrelationdocument", "Content", "documentid=" + ID); This.lbSize.Text = dv. Documentsize.tostring (); This.txtUserName.Text = dv.                Userid.tostring (); This.hf_CustomerDocumentID.Value = dv.                Customerdocumentid.tostring (); Lbupdatetime.text = dv.                            Uploadtime.tostring (); }}///<summary>///Save edits///</summary>//<param name= "Sen Der "></param>//<param name=" E "></param> protected void btnSubmit_Click (object sender            , EventArgs e) {biocrmcorrelationdocument document = new Biocrmcorrelationdocument (); Document. DocumentID =int. Parse (request.querystring["ID").            ToString ()); Document.                   Subject = This.txtsubJect.Text; Document. UserID =int. Parse (session["Userid").            ToString ()); Document.            Remark = This.txtRemark.Text; Document.                        Documentlevel = This.ddlLevel.SelectedValue; if (this. Fileupload1.hasfile) {DocumenT.name = DateTime.Now.ToString ("YyyyMMdd hhmmss") + this.                Fileupload1.filename; Document. Content = this.                 Fileupload1.filebytes; Document. Type=this.                FileUpload1.PostedFile.ContentType; Document.                Uploadtime = DateTime.Now; Document. DocumentSize = this.                FileUpload1.FileContent.Length; Document. Exetendname = System.IO.Path.GetExtension (this.            Fileupload1.filename); } else {document.                Name = This.lbName.Text; Document.                Content = filecontent; Document.                Type = This.lbType.Text; Document.                Uploadtime =convert.todatetime (Lbupdatetime.text); Document. DocumentSize =long.                Parse (This.lbSize.Text); Document.            Exetendname = This.lbExtendName.Text;            }//physical file Upload string filepath = Server.MapPath (@ "\files\crmfiles\");           if (comm.fileexists (filepath + this.lbName.Text)) {comm.filedelete (filepath + this.lbName.Text); } comm.fileupload (this. FILEUPLOAD1, filepath, document.                        Name);            BIOCRMCORRELATIONDOCUMENTBLL DOCUMENTBLL = new BIOCRMCORRELATIONDOCUMENTBLL (); Document information is added including file upload (converted to binary array after uploading) int count= DOCUMENTBLL.            Biocrmcorrelationdocumentupdate (document); Document Information added successfully if (count! = 0) {biocrmcustomerdocument customerdocument = new Biocrmcust                Omerdocument (); Customerdocument. Customerdocumentid = Int.                Parse (This.hf_CustomerDocumentID.Value); Customerdocument. CustomerID = Int.                Parse (This.txtCustomerID.Text); Customerdocument.                Deletestate =cbdelete.checked; Customerdocument. DocumentID = document.                DocumentID;                   BIOCRMCUSTOMERDOCUMENTBLL CUSTOMERDOCUMENTBLL = new BIOCRMCUSTOMERDOCUMENTBLL (); int count1= CUSTOMERDOCUMENTBLL. Biocrmcustomerdocumentupdate (cUstomerdocument); if (Count1 = = 0) {sqlcomm.deletetablebycondition ("biocrmcorrelationdocument", "wh ere documentid= "+ document.                   DocumentID);                   } else {Response.Redirect ("documentlistshow.aspx"); }            }        }

Different roles to query for different documents:

         <summary>        ///query all contact information        ///</summary> private void Getallpagelist ()        {            string ID = session["Userid"]. ToString ();            Condition = "and userid=" + ID;            if (UserLogin.user.RoleId = = 8)            {                condition = "or UserID! =" + id;            }            This. Aspnetpager1.recordcount = Sqlcomm.getdatacountbycondition ("dbo. View_doucmentinfo ", condition);            This. Aspnetpager1.pagesize = PageSize;            This. Gridview1.datasource = Sqlcomm.getdatabypageindex ("dbo. View_doucmentinfo "," * "," documentid ", Condition, pageindex, pagesize);            This. Gridview1.databind ();                   }

ERP system Upload Document information download (18)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.