Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can anyone suggest the best procedure to...

Status
Not open for further replies.

iara

Programmer
Oct 2, 2002
17
0
0
HN
Can anyone suggent me the procedure to reading a file and then writing to an array specific parts of a binary file, or maybe Im thinking of writing it to another file instead of using an array. I know I have to use the System.IO stream classes. Well thanks in advanced.
 
Yeah.. I wrote these two functions to serialize a file to send over a web service. They will do the trick for you.

public static bool UploadFile(string strPath, byte[] btFile)
{
try
{
FileStream objFileStream = new FileStream(strPath, FileMode.CreateNew, FileAccess.Write, FileShare.None);
objFileStream.Write(btFile, 0, btFile.Length);
objFileStream.Close();
}
catch (FieldAccessException e)
{
// write to application log
return false;
}
return true;
}
public static byte[] DownloadFile(string strFile)
{
byte[] btFile;
try
{
FileStream objFileStream = new FileStream(strFile, FileMode.Open, FileAccess.Read, FileShare.Read);
btFile = new Byte[objFileStream.Length];
objFileStream.Read(btFile, 0, (int) objFileStream.Length);
objFileStream.Close();
}
catch (Exception e)
{
return null;
}
return btFile;
}
 
Thanks it was a great help.Now I am trying to just a line from the file to a richtextbox, I guess the properties of the .rtf file are not kept.
{
//READ A LINE
String scfile=dlgOpen.FileName;
StreamReader srReadline=new StreamReader ((System.IO.Stream )File.OpenRead(scfile),System.Text.Encoding.ASCII );
srReadline.BaseStream.Seek (0,SeekOrigin.Begin );
while(srReadline.Peek () > -1)
rtb_try.Rtf =srReadline.ReadLine() ;

srReadline.Close();
}
If you know a way of keeping the properties it would be alot of help..
thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top