Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Picture this - Storing an Image to an Image field
Message
De
06/04/2005 09:20:51
 
 
À
06/04/2005 08:47:17
Information générale
Forum:
ASP.NET
Catégorie:
Bases de données
Versions des environnements
Environment:
VB.NET 1.1
OS:
Windows XP
Network:
Windows XP
Database:
MS SQL Server
Divers
Thread ID:
01000118
Message ID:
01001870
Vues:
39
Thanks Simplicio, I will use this technique for storing and viewing images. This is a huge improvement over the other techniques I have been trying.


>hi glen this is how i view image. i just call this page with a parameter value equal to its PK.
>
>
>
>
>		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();
>		}
>
>		>
>
>this is how i upload. note : txtFileContents is the textfield that containts path
>
>
>
>
>	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')		
>
>
>
>
>
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform