Hello,
I am really struggling on this. A quick solution would be great before I go crazy, thanks.
I have a problem trying to get images working in RadGrid. I am using an existing SQL table (SQL 2005 Developer) which has product images stored as column type image. These display fine in Winforms radgrid controls. Under asp.net though I keep getting errors about invalid parameters.
The exception is shown
Server Error in '/GP_V1_00' Application.
Exception Details: System.ArgumentException: Parameter is not valid.
Source Error:
Stack Trace:
Version Information: Microsoft .NET Framework Version:2.0.50727.3082; ASP.NET Version:2.0.50727.3082
My code is shown here.
Code behind code for handling images or adding them...
I am really struggling on this. A quick solution would be great before I go crazy, thanks.
I have a problem trying to get images working in RadGrid. I am using an existing SQL table (SQL 2005 Developer) which has product images stored as column type image. These display fine in Winforms radgrid controls. Under asp.net though I keep getting errors about invalid parameters.
The exception is shown
Server Error in '/GP_V1_00' Application.
Parameter is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.ArgumentException: Parameter is not valid.
Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
|
Stack Trace:
[ArgumentException: Parameter is not valid.] System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData) +1062843 System.Drawing.Image.FromStream(Stream stream) +8 Telerik.Web.UI.ImageFilterHelper.CreateImgFromBytes(Byte[] image) +99 [ArgumentException: The provided binary data may not be valid image or may contains unknown header] Telerik.Web.UI.ImageFilterHelper.CreateImgFromBytes(Byte[] image) +173 Telerik.Web.UI.BinaryImageTransformationFilter.ProcessImageInternal(Byte[] image) +53 Telerik.Web.UI.BinaryImageTransformationFilter.ProcessImage(Byte[] image) +54 Telerik.Web.UI.BinaryImageFilterProcessor.ProcessFilters(Byte[] imageData) +188 Telerik.Web.UI.RadBinaryImage.ProcessImageData() +124 Telerik.Web.UI.RadBinaryImage.OnPreRender(EventArgs e) +41 System.Web.UI.Control.PreRenderRecursiveInternal() +80 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842 |
Version Information: Microsoft .NET Framework Version:2.0.50727.3082; ASP.NET Version:2.0.50727.3082
My code is shown here.
<telerik:RadGrid ID="RadGridImages" runat="server" DataSourceID="SqlDataSourceImages" |
GridLines="None" AutoGenerateColumns="False"> |
<MasterTableView DataKeyNames="Id" DataSourceID="SqlDataSourceImages"> |
<Columns> |
<telerik:GridBoundColumn DataField="Id" DataType="System.Int32" HeaderText="Id" ReadOnly="True" |
SortExpression="Id" UniqueName="Id"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="Product_Id" DataType="System.Int32" HeaderText="Product_Id" |
SortExpression="Product_Id" UniqueName="Product_Id"> |
</telerik:GridBoundColumn> |
<telerik:GridBinaryImageColumn DataField="image" HeaderText="Image" UniqueName="ProdImage" |
ImageAlign="Middle" ImageHeight="150px" ImageWidth="200px" ResizeMode="Fit" DataAlternateTextField="Id" |
DataAlternateTextFormatString="Image of {0}"> |
</telerik:GridBinaryImageColumn> |
</Columns> |
</MasterTableView> |
</telerik:RadGrid> |
Code behind code for handling images or adding them...
protected void ButtonAddImage_Click(object sender, EventArgs e) |
{ |
if (RadGridProducts.SelectedItems.Count < 1 || (string.IsNullOrEmpty(FileUploadImage.FileName))) |
return; |
string strId = ((GridDataItem)RadGridProducts.SelectedItems[0]).GetDataKeyValue("Id").ToString(); |
// Create the image |
byte[] imageData = this.FileUploadImage.FileBytes; |
SaveImage(strId, imageData); |
} |
private void SaveImage(string strImageId, byte[] imageData) |
{ |
try |
{ |
this.SqlDataSourceImages.InsertCommand = "INSERT INTO Product_Image (Product_Id, Image) " + |
"VALUES ('" + strImageId + "','" + imageData + "')"; |
try |
{ |
this.SqlDataSourceImages.Insert(); |
} |
catch (SqlException sqlex) |
{ |
this.LabelStatus.Text = "An exception stopped the transaction being created\r\n" + sqlex.ToString(); |
} |
} |
catch (Exception ex) |
{ |
} |
} |