.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
MarieAdela
Imran Ghani
Post New Web Links

How do you filestream read a group of bytes instead of byte by byte?

Posted By:      Posted Date: September 18, 2010    Points: 0   Category :ASP.Net
 
If the following code is seeking to a specific byte of the file, then reading it byte by byte... then how do Itell it to read a group of bytes ?  for example, I want to read 10 bytes at a time and store into some char array.thanksfileStream.Seek(0, SeekOrigin.Begin); //seek to first byte ch = (char) fileStream.ReadByte(); Console.WriteLine("First value is " + ch);


View Complete Post


More Related Resource Links

Converting ReportDocument object into byte array ?

  

Hi All,

          Is it possible to convert the Report Document object as a byte array and store it in SQL , later retrieve and assing it to a report ?

 


Cannot convert type 'object[]' to 'byte[]'

  

I am doing this .. and i want to convert object array to byte array. How should I do that?

Object[] myVal = um.myData;

Byte[] byteArray = (Byte[])myVal;


Converting a byte array to a gif

  

Hi there,

I am currently in the process of trying to convert a byte array into a gif format. So far I have done this:

                        byte[] gif = Convert.FromBase64String(myByteArray);
                        MemoryStream ms = new MemoryStream(gif);
                        Bitmap image = new Bitmap(ms);
                        string pathToSave = Server.MapPath("~/_temp/");
                        iconUrl = string.Format("{0}/{1}.gif", pathToSave, fileName);
                        image.Save(iconUrl);


When this code block executes, I get the following error:

A generic error occurred in GDI+.

I have made sure that I have the correct permissions for the _temp folder, but I am not sure if I am trying to convert "bad bytes". Could someone perhaps shed some light on this error? 


Conversion of Byte Array to Memory stream

  

how to convert byte array to memory stream in vb.net.


How to Pass higher Length of Byte Array to the remoting method

  
Dear all,I am using a windows application and the businness logic is present in the remote server.Once particular method takes bytearray as input parameter...Whenever the method call is made the function returns value .This is limited for the particular bytearray length. (4109228 bytes).If the length of bytearray crosses 4109228 bytes.I am getting an error that "input stream is not valid binary format".How to Pass higher Length of Byte Array to the remoting method... Greater than 4 MB?I believe something is missing in web.config or app.config...?What could be the issue...? Any sugesstions are welcome....ThanksRavikumar

Binding byte[] to image control in navigation application leaks

  
Hi there, I have a (minimal) navigation application with two pages. Page1 contains an image. Switching between pages is done via a buttonhandler in code behind, for instance, (this.NavigationService.Navigate(new Page2())) The image is loaded in code behind via: private void LoadImage() { string fileName = "./images/image.bmp"; if (!new FileInfo(fileName).Exists) throw new Exception("File name doesn't exist"); using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { this.ImageData2 = new byte[fs.Length]; fs.Read(this.ImageData2, 0, System.Convert.ToInt32(fs.Length)); fs.Close(); } } ImageData2 is a byte[] property that sends a propertychange event on changing. ImageData2 is bound to an image in xaml: <Image Grid.Row="1" Source="{Binding Path=ImageData2, Mode=OneTime}"/> When we unload Page1 the following clean up code is executed private void Page_Unloaded(object sender, RoutedEventArgs e) { this.ImageData2 = null; GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); } Now, when I start changing pages, I expect the Page we leave to unload, so the GC removes the byte array. However, it doesn't. Am I missing something? Binding the image to a BitmapImage (ImageData1, as you might have guessed:-) ) doesn't leak.

FormView with empty Byte Fields

  
I have a FormView with a byte field.  The field is not required and if I don't enter a value, I get an error that the value is not acceptable in a byte field.  I can replace the null value with 0 but I would prefer not to. What is the best way to handle this so that if I do not enter a value in a byte (or int16) field to insert a null value (or whatever they do in the ASP.net).   THanks for your help. 

how to split byte array

  
hi all,how to split byte array?for eg when i convert byte array to string it will come like as followsbytetostring="%%90,53453%%20,%%20,434234my requirement is i need to split bytearray using the string byte "%%"and need to find out hex value of each linebyte to hex i did like as followsDim strTemp1 As New StringBuilder(Bytes.Length * 2)                                    For intIndex1 = offset To offset + count - 1  'offset is 0 and count is length of the string                                        strTemp1.AppendFormat("{0:x2}", Bytes(intIndex1))                                    Nextthis function resulting the hex value of full string.I need hex value of each byte splitted with "%%"

Converting a System.Windows.Control.Image object to byte array.

  
Hi i need to convert a specific System.Windows.Control.Image object into an (int) array, because i'm trying to convert a silverlight application into a wpf project. private void createGi02GradBrush()<br/> {<br/> WriteableBitmap oWriteableBitmap = new WriteableBitmap(256, 256);<br/> Image oImage = new Image();<br/> oImage.Arrange(new Rect(0, 0, 256, 256));<br/> oImage.Measure(new Size(256, 256));<br/> oImage.Source = new WriteableBitmap(256, 256);<br/> Gi02GradShaderEffect oGi02GradShaderEffect = new Gi02GradShaderEffect();<br/> oGi02GradShaderEffect.pArray = oPImageBrush;<br/> oGi02GradShaderEffect.gi1GradArray = oGi1GradImageBrush;<br/> oImage.Effect = oGi02GradShaderEffect;<br/> oWriteableBitmap.Render(oImage, null);//here<br/> oWriteableBitmap.Invalidate(); <br/> this.oGi02GradImageBrush = new ImageBrush();<br/> this.oGi02GradImageBrush.ImageSource = oWriteableBitmap;<br/> } I've found some similar topics however Image object is not the same and most of its methods aren't available. Here I'm rendering a writablebitmap with a given Image object, but in wpf we need an array. oWriteableBitmap.Render(oImage, null); Any idea? Thanks. Joseph.  

Load byte[] into a ListView like in a hex editor (each byte should be an item)

  
Hi, I am writing some sort of Hex Editor in C# .NET 3.5 WPF. My input is a binary file, which can be very large (at least 10MB). I want to benfit from WPF's UI virtualization. For that I've tried using the DataGrid or the ListView. However, those 2 have a concept of each row being an item, and the hex dump means each cell is an item. Trying to copy the byte[] to a DataTable or a new class that implements IEnumerable takes too much memory and hangs the application. Also creating many strings / TextBoxes will be very expensive. Example of an input: 37 AA B1 00 01 05 03 33 45 66 23 45 67 43 32 12 47 5A 61 70 01 05 83 99 45 45 23 25 67 43 32 12 56 34 45 67 I would like to show like this: 37 AA B1 00 01 05 03 33 45 66 23 45 67 43 32 12 47 5A 61 70 01 05 83 99 45 45 23 25 67 43 32 12 56 34 45 67 I've encountered the wrap panel (which might suit as well with Horizontal orientation) but wrap panel has no virtualization. I'm fairly new to WPF, but I've read a lot for 2 weeks in all the web... and tried a lot!!! But still, I can't seem to find a good solution to my problem. Please help :( Thanks in advance, Michal.

write Data to Byte[ ] array

  
Hi All.i hava a data in string variable for example :string Data = "0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAPgADAP7/"and i want to convert this data to binary format so that i can insert this data to Image data field in Database .. can u please give me the solution.Thanks in advance

Exporting image byte stream to Excel

  

Hi,

I am working on implementing exporting data to Excel functionality in ASP.Net and as part of that an image stored in the database has to be exported to Excel along with some other content. I am able to write the content to Excel by referring to the required cells. Is it possible to write the image byte stream read from the database which is in the form of byte[] directly to Excel sheet without saving that to physical disk?

Please suggest how to write image byte stream to Excel without saving the image to physical disk?

Thank you,

Raghu


SQL Server 2008: When creating database with filestream group pc hangs

  
Hello,

I am facing this STRANGE problem with sql server 2008. When I try to create a new database with filestream group my system hangs. When I restart pc by direct power off and then on, I cannot see the new database but at the given location I could see that database files and filestream group has been created. 

Solutions Tried.
Uninstall, download new version then reinstall but to no use.
Set maximum permissions to current user (according to my knowledge).
Using Mix mode authentication.


PC configuraion:
XP Home Edition SP2,
Intel Dual Core 2.0 GHZ Processor
4GB Ram,
SQL Server express SP1 installed on NTFS Partition
Plenty of Disk Space
Comodo Firewall pro, Avast Antivirus ( Already tried to stop firewall and antivirus still no use)

Any help would be appreciated.

Why can't you increment ushort or byte variables (+1)??

  

According to the C# built-in types table at http://msdn.microsoft.com/en-us/library/ya5y69ds.aspx,

the ushort is a 16-bit unsigned integer.  The byte is an 8-bit unsigned integer.

So when I declare:

public byte x;

ushort y;


Neither of those, I can not do the following:

x = x+1;

y=y+1; 

i get an error: "Cannot implicitly convert type "int" to "ushort" or to "byte".


Why is this?  They are both integer-grade data types?  I don't want to use the "int" type because that is a 32-bit signed integer, requiring more memory than I need.


thanks


Combine two byte arrays

  

I have two byte arrays from rdlc reports.

I need to create a pdf combining both the byte arrays.

My code is

Warning[] warnings;
                string[] streamIds;
                string mimeType = string.Empty;
                string encoding = string.Empty;
                string extension = string.Empty;

                bytes = rptViewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);

                bytes1 = RunReport(21316228, "82", 7);

                byte[] combined = new byte[bytes.Length + bytes1.Length];
                bytes.CopyTo(combined, 0); 
             &

Combine two byte arrays from rdlc to create a pdf

  

I have two byte arrays from rdlc reports.

I need to create a pdf combining both the byte arrays.

My code is

Warning[] warnings;
                string[] streamIds;
                string mimeType = string.Empty;
                string encoding = string.Empty;
                string extension = string.Empty;

                bytes = rptViewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);

                bytes1 = RunReport(21316228, "82", 7);

                byte[] combined = new byte[bytes.Length + bytes1.Length];
                bytes.CopyTo(combined, 0); 
             &

Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend