> > > private void Page_Load(object sender, System.EventArgs e) > { > > > > int intItemID; > SqlConnection conMyData; > string strSelect; > SqlCommand cmdSelect; > SqlDataReader dtrSearch; > > intItemID = Convert.ToInt32(Request.Params["tranid"]); > > conMyData = new SqlConnection( ConfigurationSettings.AppSettings["connectionString"]); > strSelect = "SELECT DocBin, FileExtension FROM dbo.vWebDocs" > + " WHERE PkTranID=@itemID"; > cmdSelect = new SqlCommand( strSelect, conMyData ); > cmdSelect.Parameters.Add( "@itemID", intItemID ); > conMyData.Open(); > dtrSearch = cmdSelect.ExecuteReader(); > if ( dtrSearch.Read()) > { > Response.ClearHeaders(); > > switch(dtrSearch["FileExtension"].ToString().Trim().ToLower()) > { > case "pdf": > Response.ContentType = "application/pdf"; > break; > case "gif" : > Response.ContentType = "image/jpeg"; > break; > > case "bmp" : > Response.ContentType = "image/jpeg"; > break; > > case "jpg" : > Response.ContentType = "image/jpeg"; > break; > > case "png" : > Response.ContentType = "image/jpeg"; > break; > > case "xls" : > Response.ContentType = "application/vnd.ms-excel"; > Response.Charset = ""; > break; > > > case "doc" : > Response.ContentType = "application/msword"; > Response.Charset = ""; > break; > > > > default: > Response.AddHeader("content-disposition", "attachment; filename=downloadedFile."+dtrSearch["FileExtension"].ToString().Trim().ToLower()); > Response.ContentType = "application/octet-stream"; > break; > > > } > > > > Response.BinaryWrite( (byte[])dtrSearch["DocBin"] ); > } > dtrSearch.Close(); > conMyData.Close(); > } > > >>
> > Boolean HasError ; > HasError =false; > > > > this.btnUpload.Enabled=false; > string strFileExtension; > string strFileType; > Boolean hasError; > int intFileLen; > Stream objStream; > hasError=false; > if ( txtFileContents.PostedFile != null ) > { > > int fileLen = txtFileContents.PostedFile.FileName.Length; > strFileExtension = txtFileContents.PostedFile.FileName.Substring(fileLen-4,4); > strFileType= strFileExtension.ToLower().Substring(1,strFileExtension.Length-1); > > > intFileLen = txtFileContents.PostedFile.ContentLength; > byte[] arrFile = new byte[intFileLen]; > objStream = txtFileContents.PostedFile.InputStream; > objStream.Read( arrFile, 0, intFileLen ); > > > > SqlCommand cmdSelect; > > > > SqlParameter parPkTranID; > SqlParameter parFKUSRID; > SqlParameter parDocTypeID; > SqlParameter parValuedate; > SqlParameter parRefNum; > SqlParameter parFilenameEx; > SqlParameter parDeptID; > SqlParameter parDocBinary; > SqlParameter parDocMemo; > SqlParameter parLocation; > SqlParameter parFkCompanyID ; > > cmdSelect = new SqlCommand("spInsertNewWebTransaction", oConn ); > cmdSelect.CommandType = CommandType.StoredProcedure; > > parPkTranID=cmdSelect.Parameters.Add("@PkTranID",SqlDbType.BigInt); > parPkTranID.Direction = ParameterDirection.Output ; > > parFKUSRID=cmdSelect.Parameters.Add("@FKUSRID",SqlDbType.Int ); > parDocTypeID=cmdSelect.Parameters.Add("@DocTypeID",SqlDbType.Int ); > parValuedate=cmdSelect.Parameters.Add("@Valuedate",SqlDbType.SmallDateTime); > parRefNum=cmdSelect.Parameters.Add("@RefNum",SqlDbType.VarChar,50 ); > parFilenameEx=cmdSelect.Parameters.Add("@FilenameExt",SqlDbType.VarChar,10 ); > parDeptID=cmdSelect.Parameters.Add("@FkCustEmpVenIDBranchID",SqlDbType.Int ); > parDocBinary=cmdSelect.Parameters.Add("@DocBinary",SqlDbType.Image); > parDocMemo=cmdSelect.Parameters.Add("@DocMemo",SqlDbType.VarChar,200 ); > parLocation=cmdSelect.Parameters.Add("@Location",SqlDbType.VarChar,200 ); > parFkCompanyID=cmdSelect.Parameters.Add("@FkCompanyID",SqlDbType.Int ); > > parPkTranID.Value =0; > parFKUSRID.Value =Double.Parse(Request.Cookies["UserInfo"].Values["UserID"]); > parDocTypeID.Value =Double.Parse( this.cboDocType.SelectedValue) ; > parValuedate.Value =DateTime.Parse( this.txtDate.Text) ; > parRefNum.Value =this.txtRefNum.Text ; > parFilenameEx.Value =strFileType; > parDeptID.Value =Double.Parse(Request.Cookies["UserInfo"].Values["UserDeptID"]); > parDocMemo.Value = this.txtDescription.Text.Trim(); > parLocation.Value = this.txtLocation.Text.Trim(); > parDocBinary.Value =arrFile ; > parFkCompanyID.Value = this.cboCompanyID.SelectedValue; > try > { > oConn.ConnectionString =ConfigurationSettings.AppSettings["connectionString"]; > oConn.Open(); > cmdSelect.ExecuteNonQuery(); > oConn.Close(); > } > catch (Exception ex) > { > hasError=true; > >>
> > >ALTER procedure spInsertNewWebTransaction > @PkTranID IDEN_BIG out, > @FKUSRID iden_id_small, > @DocTypeID iden_id_small, > @Valuedate smalldatetime, > @RefNum varchar(50), > @FilenameExt varchar(10), > @FkCustEmpVenIDBranchID iden_id_small, > @DocBinary image, > @DocMemo varchar(200), > @Location varchar(50), > @FkCompanyID iden_id_small >as > > >insert into vWebDocs(Location,DocMemo,FkDocType,FkDeptID ,fkusrid,RefNo,istmp,fktrantypeID,valueDate,FileExtension,DocBin,FkCompanyID ) VALUES > (@Location ,@DocMemo,@DocTypeID,@FkCustEmpVenIDBranchID ,@FKUSRID,@RefNum,0,235,@Valuedate,@FilenameExt,@DocBinary,@FkCompanyID ) > >select @PkTranID=IDENT_CURRENT('vWebDocs') > > > > >