I am working on a web site developed in ASP.Net 2.0. I want to read image file from Images folder and want to pass the image to a dataset? Can anybody help me how can I do that?
FileStream fs = new FileStream(Server.MapPath("../Images/Image Not Available.jpg"), FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
but the line ds.Tables[0].Rows[0]["DocImage"] = br.ReadBytes(br.BaseStream.Length); is throwing error i.e.
Error 20 The best overloaded method match for 'System.IO.BinaryReader.ReadBytes(int)' has some invalid arguments E:\Joel Data\PipeTracking_GI\PipeTracking_GI\MainCtrls\ctrlReportOffBargeInventory.ascx.cs 71 56 PipeTracking_GI
Error 21 Argument '1': cannot convert from 'long' to 'int' E:\Joel Data\PipeTracking_GI\PipeTracking_GI\MainCtrls\ctrlReportOffBargeInventory.ascx.cs 71 69 PipeTracking_GI
why this is happening and whats the solution of it ?
azharrahi
Member
127 Points
230 Posts
How to read image file ?
Apr 17, 2008 04:50 PM|LINK
Hello How are all here ?
I am working on a web site developed in ASP.Net 2.0. I want to read image file from Images folder and want to pass the image to a dataset? Can anybody help me how can I do that?
Thanks
rmaiya
Star
11502 Points
1790 Posts
Re: How to read image file ?
Apr 17, 2008 05:07 PM|LINK
http://www.codeproject.com/KB/asp/Display_Images_from_Data.aspx
http://aspalliance.com/1322_Displaying_Images_in_ASPNET_Using_HttpHandlers
(MCSD.NET, MCAD.NET, MCDBA)
[Don't forget to click on Mark as answer on the post that helped you ]
azharrahi
Member
127 Points
230 Posts
Re: How to read image file ?
Apr 17, 2008 06:14 PM|LINK
rmaiya
Star
11502 Points
1790 Posts
Re: How to read image file ?
Apr 17, 2008 06:15 PM|LINK
YES
(MCSD.NET, MCAD.NET, MCDBA)
[Don't forget to click on Mark as answer on the post that helped you ]
azharrahi
Member
127 Points
230 Posts
Re: How to read image file ?
Apr 17, 2008 07:34 PM|LINK
How? can you give me any help or link please ?
azharrahi
Member
127 Points
230 Posts
Re: How to read image file ?
Apr 17, 2008 07:59 PM|LINK
FileStream fs = new FileStream(Server.MapPath("../Images/Image Not Available.jpg"), FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
ds.Tables[0].Rows[0]["DocImage"] = br.ReadBytes(br.BaseStream.Length);
br = null;
fs.Close();
fs = null;
but the line ds.Tables[0].Rows[0]["DocImage"] = br.ReadBytes(br.BaseStream.Length); is throwing error i.e.
Error 20 The best overloaded method match for 'System.IO.BinaryReader.ReadBytes(int)' has some invalid arguments E:\Joel Data\PipeTracking_GI\PipeTracking_GI\MainCtrls\ctrlReportOffBargeInventory.ascx.cs 71 56 PipeTracking_GI
Error 21 Argument '1': cannot convert from 'long' to 'int' E:\Joel Data\PipeTracking_GI\PipeTracking_GI\MainCtrls\ctrlReportOffBargeInventory.ascx.cs 71 69 PipeTracking_GI
why this is happening and whats the solution of it ?
Hong-Gang Ch...
All-Star
74695 Points
6767 Posts
Microsoft
Re: How to read image file ?
Apr 22, 2008 05:26 AM|LINK
Hi azharrah,
Please check the method of ReadBytes, this method should be work with a int type parameter, but br.BaseStream.Length is a long type!
So please convert br.BaseStream.Length to int type to solve you problem.
Hope it helps,
Hong Gang
If you have any feedback about my replies,please contactmsdnmg@microsoft.com.
Microsoft One Code Framework