473,395 Members | 1,949 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,395 software developers and data experts.

Reading from a file, what am i doing wrong here ?

I can't see what Ive done wrong with the following, would someone help
please.
I'm trying to read rich text from a file. Ive tested the file using a hex
editor and the contents have been written correctly. When i read back the
file, the result is returned as the file name and not the file contents!!
_BodyFilename is defined by Path.GetTempFileName()
thanks :)
(visual studio 2005 on XP pro)
string result = "";
if (File.Exists(_BodyFilename))
{
StreamReader sr = new StreamReader(_BodyFilename);
try
{
result = sr.ReadToEnd();
}
finally
{
sr.Close();
}
}
return result;
Sep 28 '07 #1
5 1159
Path.GetTempFileName() return a temproray file name with zero sies.
that's why u are not getting any output

"Claire" wrote:
I can't see what Ive done wrong with the following, would someone help
please.
I'm trying to read rich text from a file. Ive tested the file using a hex
editor and the contents have been written correctly. When i read back the
file, the result is returned as the file name and not the file contents!!
_BodyFilename is defined by Path.GetTempFileName()
thanks :)
(visual studio 2005 on XP pro)
string result = "";
if (File.Exists(_BodyFilename))
{
StreamReader sr = new StreamReader(_BodyFilename);
try
{
result = sr.ReadToEnd();
}
finally
{
sr.Close();
}
}
return result;
Sep 28 '07 #2
The file has data in it which was written "earlier". I just generated the
temp file using gettempfilename.
As i said, I tested the file using a hex editor and it contained the correct
contents.
thank you anyway :)

"Som Nath Shukla" <So***********@discussions.microsoft.comwrote in message
news:1C**********************************@microsof t.com...
Path.GetTempFileName() return a temproray file name with zero sies.
that's why u are not getting any output

"Claire" wrote:
>I can't see what Ive done wrong with the following, would someone help
please.
I'm trying to read rich text from a file. Ive tested the file using a hex
editor and the contents have been written correctly. When i read back the
file, the result is returned as the file name and not the file contents!!
_BodyFilename is defined by Path.GetTempFileName()

Sep 28 '07 #3
On Sep 28, 7:23 am, "Claire" <c...@nospam.comwrote:
I can't see what Ive done wrong with the following, would someone help
please.
I'm trying to read rich text from a file. Ive tested the file using a hex
editor and the contents have been written correctly. When i read back the
file, the result is returned as the file name and not the file contents!!
_BodyFilename is defined by Path.GetTempFileName()
thanks :)
(visual studio 2005 on XP pro)

string result = "";
if (File.Exists(_BodyFilename))
{
StreamReader sr = new StreamReader(_BodyFilename);
try
{
result = sr.ReadToEnd();}

finally
{
sr.Close();}
}

return result;
Hi Claire,
For what it's worth, I created an RTF using wordpad, and ran your code
and I got the contents of the file just fine. Perhaps you could post
the code that generates the file?

By the way I replaced _BodyFilename with a constant that points to the
file I generated, like so:
string _BodyFilename = @"c:\foo.rtf";

Not sure it matters, but I'm also running VS.NET 2005 under XP Pro.
John

Sep 28 '07 #4
every time u write Path.GetTemFilename() generates a new temporary file.
send me ur full code .

"Claire" wrote:
The file has data in it which was written "earlier". I just generated the
temp file using gettempfilename.
As i said, I tested the file using a hex editor and it contained the correct
contents.
thank you anyway :)

"Som Nath Shukla" <So***********@discussions.microsoft.comwrote in message
news:1C**********************************@microsof t.com...
Path.GetTempFileName() return a temproray file name with zero sies.
that's why u are not getting any output

"Claire" wrote:
I can't see what Ive done wrong with the following, would someone help
please.
I'm trying to read rich text from a file. Ive tested the file using a hex
editor and the contents have been written correctly. When i read back the
file, the result is returned as the file name and not the file contents!!
_BodyFilename is defined by Path.GetTempFileName()


Sep 28 '07 #5
you should use Path.GetFilename(Filepath)
instead of GetTempFilename
baoth are different function.
GetTempFilename does not take any argument and generate a temproray file
..tmp extension

"Claire" wrote:
The file has data in it which was written "earlier". I just generated the
temp file using gettempfilename.
As i said, I tested the file using a hex editor and it contained the correct
contents.
thank you anyway :)

"Som Nath Shukla" <So***********@discussions.microsoft.comwrote in message
news:1C**********************************@microsof t.com...
Path.GetTempFileName() return a temproray file name with zero sies.
that's why u are not getting any output

"Claire" wrote:
I can't see what Ive done wrong with the following, would someone help
please.
I'm trying to read rich text from a file. Ive tested the file using a hex
editor and the contents have been written correctly. When i read back the
file, the result is returned as the file name and not the file contents!!
_BodyFilename is defined by Path.GetTempFileName()


Sep 28 '07 #6

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

Similar topics

5
by: Ken | last post by:
Hello, I'm trying to read a Blob from Oracle and then write it to an audio file(.AU). I'm using Visual Studio.Net 2003 (VB). I can't seem to get my code to work. Will someone take a look at it...
3
by: SB | last post by:
Hello. I have an input file which is laid out in the following manner... Name Day 1 am time 1 am time 2 appointment pm time 1 pm time 2 appointment Day 2
3
by: Nick | last post by:
I have found a class that compresses and uncompresses data but need some help with how to use part of it below is the deflate method which compresses the string that I pass in, this works OK. At...
4
by: supster | last post by:
I have the full file path of a file stored as a string and I'de like to get the file size in bytes. What is the most efficient way of doing this with a static method from the File class or...
3
by: dale zhang | last post by:
Hi, I am trying to read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp The article author is using PictureBox for windows...
6
by: al jones | last post by:
I picked a good project to try to learn to use VS - and up till now everything has worked the way I expect. The code is from a VS.net class, which I picked up on the web, from which I've extracted...
7
by: John Bowman | last post by:
Hi All, I'm fairly new to XML, so I presume I'm doing something obviously dense here, but here it goes. Below is an XML file that was extracted from a test Windows Installer .MSP (patch) file...
21
by: EdUarDo | last post by:
Hi all, I'm not a newbie with C, but I don't use it since more than 5 years... I'm trying to read a text file which has doubles in it: 1.0 1.1 1.2 1.3 1.4 2.0 2.1 2.2 2.3 2.4 I'm doing...
6
by: Bigshot | last post by:
Following on from my "Multidimensional arrays in C" post, I wanted to get some more specific help to see what I am doing wrong. My program is supposed to read in a network topology file and create a...
1
by: stoogots2 | last post by:
I have written a Windows App in C# that needs to read a text file over the network, starting from the end of the file and reading backwards toward the beginning (looking for the last occurrence of a...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.