473,399 Members | 3,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Streamwriter.Write error...

Hi

I keep getting this error if Im using UTF7?

An unhandled exception of type 'System.ArgumentException' occurred in
mscorlib.dll

Additional information: Conversion buffer overflow.

Only trying to change a path of an image to an binary string. can someone
help me with this error?

ps. If I use UTF8 I receive no error????
Function
private static void ConvertImages(cIni _ini)
{
FileInfo finfo = new FileInfo(_ini.FilePath);
string sline = "";
if(finfo.Exists)
{
string delimStr = ";";
char[] del = delimStr.ToCharArray();
StreamReader stream_reader;
StreamReader stream_reader_tempfile;

m_sTempPath = _ini.FilePath + "temp";

//Ensure that the file does not exist
File.Delete(m_sTempPath);
File.Copy(_ini.FilePath,m_sTempPath);
stream_reader_tempfile = new
StreamReader(m_sTempPath,System.Text.Encoding.UTF7 );//File.OpenText(m_sTempP
ath);
string sContentsTemp = stream_reader_tempfile.ReadToEnd();
stream_reader_tempfile.Close();

//StreamWriter streamWriter_temp = File.CreateText(m_sTempPath);
StreamWriter streamWriter_temp = new
StreamWriter(m_sTempPath,true,System.Text.Encoding .UTF7);

using(stream_reader = new StreamReader(finfo.FullName,
System.Text.Encoding.UTF7))
{
sline = "";
FileStream fsImages;
while((sline = stream_reader.ReadLine()) != null)
{
string[] sArr = sline.Split(del,24);

for(int i = 3; i < 8; i++)
{

if(sArr[i].ToString() != String.Empty)
{
FileInfo fiMynd = new FileInfo(sArr[i].ToString());
if(fiMynd.Exists)
{
fsImages = new FileStream(fiMynd.FullName, FileMode.Open,
FileAccess.ReadWrite);
BinaryReader br = new BinaryReader(fsImages);
br.BaseStream.Position = 0;
byte[] barrImage = br.ReadBytes((int)br.BaseStream.Length);
string sBI = sContentsTemp.Replace(sArr[i].ToString(),
System.Text.UTF7Encoding.UTF7.GetString(barrImage) );
/************************************************** */
streamWriter_temp.Write(sBI); //ERROR
/************************************************** */
fsImages.Close();
}
}
}
}
}

stream_reader.Close();
stream_reader_tempfile.Close();
streamWriter_temp.Close();

}

}
Jul 21 '05 #1
1 2411
Sorry guys.... its running now... :s
"Páll Ólafsson" <pa***********@skyrr.is> wrote in message
news:ul**************@TK2MSFTNGP14.phx.gbl...
Hi

I keep getting this error if Im using UTF7?

An unhandled exception of type 'System.ArgumentException' occurred in
mscorlib.dll

Additional information: Conversion buffer overflow.

Only trying to change a path of an image to an binary string. can someone
help me with this error?

ps. If I use UTF8 I receive no error????
Function
private static void ConvertImages(cIni _ini)
{
FileInfo finfo = new FileInfo(_ini.FilePath);
string sline = "";
if(finfo.Exists)
{
string delimStr = ";";
char[] del = delimStr.ToCharArray();
StreamReader stream_reader;
StreamReader stream_reader_tempfile;

m_sTempPath = _ini.FilePath + "temp";

//Ensure that the file does not exist
File.Delete(m_sTempPath);
File.Copy(_ini.FilePath,m_sTempPath);
stream_reader_tempfile = new
StreamReader(m_sTempPath,System.Text.Encoding.UTF7 );//File.OpenText(m_sTempP ath);
string sContentsTemp = stream_reader_tempfile.ReadToEnd();
stream_reader_tempfile.Close();

//StreamWriter streamWriter_temp = File.CreateText(m_sTempPath);
StreamWriter streamWriter_temp = new
StreamWriter(m_sTempPath,true,System.Text.Encoding .UTF7);

using(stream_reader = new StreamReader(finfo.FullName,
System.Text.Encoding.UTF7))
{
sline = "";
FileStream fsImages;
while((sline = stream_reader.ReadLine()) != null)
{
string[] sArr = sline.Split(del,24);

for(int i = 3; i < 8; i++)
{

if(sArr[i].ToString() != String.Empty)
{
FileInfo fiMynd = new FileInfo(sArr[i].ToString());
if(fiMynd.Exists)
{
fsImages = new FileStream(fiMynd.FullName, FileMode.Open,
FileAccess.ReadWrite);
BinaryReader br = new BinaryReader(fsImages);
br.BaseStream.Position = 0;
byte[] barrImage = br.ReadBytes((int)br.BaseStream.Length);
string sBI = sContentsTemp.Replace(sArr[i].ToString(),
System.Text.UTF7Encoding.UTF7.GetString(barrImage) );
/************************************************** */
streamWriter_temp.Write(sBI); //ERROR
/************************************************** */
fsImages.Close();
}
}
}
}
}

stream_reader.Close();
stream_reader_tempfile.Close();
streamWriter_temp.Close();

}

}

Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: ShadowOfTheBeast | last post by:
Hi, I have got a major headache understanding streamReader and streamWriter relationship. I know how to use the streamreader and streamwriter independently. but how do you write out using the...
4
by: rex64 | last post by:
I am getting an error message and I have not been able to figure hot how to fix it. I have done some research with no answers yet. I found this code that may help? Not sure what to do with it....
6
by: Don | last post by:
I'm having problems working with a streamwriter object. After closing the streamwriter and setting it to Nothing, I try to delete the file it was writing to, but I always get the following error...
6
by: GTi | last post by:
I have created a simple logger for my ASP.NET 2.0 application. I have this static function. My problem is that no data is created in the test.log file. I have added ASPNET user account...
4
by: Heron | last post by:
Hi, Could someone explain me why the following code doesn't work? The memorystream always remains with length 0. MemoryStream input = new MemoryStream();
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.