Vadim Khorishko
|
| Posted: 06/18/2002, 7:33 AM |
|
Hello All
First of all just downloded Codecharge Studio and WOW I am very impressed.
Trying in it out on a project that was written in ASP. My problem is that
all the images are not files stored on the webserver but blobs in the
database. In code charge wizard it makes those image fields memo and they
display (System.Byte[]). I am very new to ASP.NET but I tried to create a
page ViewImage.aspx with a query and return the data to the image via
src=ViewImage.aspx?ID=56 but that does not seem to trigger.
Code for ViewInage.aspx:
/// <summary>
/// Summary description for ViewImage.
/// </summary>
public class ViewImage : System.Web.UI.Page
{
public ViewImage() { }
private void Page_Load(object sender, System.EventArgs e)
{
string ImageId = Request.QueryString["ID"];
string sqlText = "SELECT photo1 FROM Listings WHERE id = " + ID;
SqlConnection connection = new SqlConnection(
ConfigurationSettings.AppSettings["Connection1String"].ToString() );
SqlCommand command = new SqlCommand( sqlText, connection);
connection.Open();
SqlDataReader dr = command.ExecuteReader();
if ( dr.Read()) //yup we found our image
{
//Response.ContentType = dr["img_contenttype"].ToString();
Response.BinaryWrite( (byte[]) dr["photo1"] );
}
connection.Close();
}
Any help would be appreciated
Thanks,
Bo
|
|
|
 |
Sanddy
|
| Posted: 06/19/2002, 9:20 AM |
|
Open a new page ... and then with the page selected in the Design View go to
Properties Exploer "Events tab".
Right-click on the "Before Show" event and select "Add Code" ...
This will switch to Code View ... now add the following code ..
//Get the QueryString
int ImgID = System.Convert.ToInt32(Request.QueryString["ImgID"]);
//Build a CodeCharge Object SqlCommand
SqlCommand imgCommand = new SqlCommand( "SELECT * FROM Images WHERE
ImageID = "+ ImgID ,
Settings.Connection1DataAccessObject );
//Fill a DataSet
DataSet imgSet = imgCommand.ExecuteDataSet ;
//Set the ContentType of the response ..
Response.ContentType = imgSet.Tables[0].Row[0]["ContentType"].ToString() ;
//Output the bytes ...
Response.OutputStream.Write((byte[])imgSet.Tables[0].Row[0]["Image"], 0,
(int)imgSet.Tables[0].Row[0]["ByteSize"]);
//End response ..
Response.End();
Hope this helps ..
CCS Fan,
Sanddy
|
|
|
 |
Bo Ugljesic
|
| Posted: 06/19/2002, 8:02 PM |
|
Thanks Sanddy for the reply. Will give it a try.
Bo
"Sanddy" <e_sanddy@yahoo.com> wrote in message
news:aeqb14$mak$1@news.codecharge.com...
> Open a new page ... and then with the page selected in the Design View go
to
> Properties Exploer "Events tab".
> Right-click on the "Before Show" event and select "Add Code" ...
>
> This will switch to Code View ... now add the following code ..
> //Get the QueryString
> int ImgID = System.Convert.ToInt32(Request.QueryString["ImgID"]);
> //Build a CodeCharge Object SqlCommand
> SqlCommand imgCommand = new SqlCommand( "SELECT * FROM Images WHERE
> ImageID = "+ ImgID ,
> Settings.Connection1DataAccessObject );
> //Fill a DataSet
> DataSet imgSet = imgCommand.ExecuteDataSet ;
> //Set the ContentType of the response ..
> Response.ContentType = imgSet.Tables[0].Row[0]["ContentType"].ToString()
;
> //Output the bytes ...
> Response.OutputStream.Write((byte[])imgSet.Tables[0].Row[0]["Image"], 0,
> (int)imgSet.Tables[0].Row[0]["ByteSize"]);
> //End response ..
> Response.End();
>
> Hope this helps ..
>
>
> CCS Fan,
> Sanddy
>
>
|
|
|
 |
|