Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Claire - 28 Sep 2007 12:23 GMT
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;
Som Nath Shukla - 28 Sep 2007 13:06 GMT
Path.GetTempFileName() return a temproray file name with zero sies.
that's why u are not getting any output

> I can't see what Ive done wrong with the following, would someone help
> please.
[quoted text clipped - 19 lines]
> }
> return result;
Claire - 28 Sep 2007 13:14 GMT
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 :)

> Path.GetTempFileName() return a temproray file name with zero sies.
> that's why u are not getting any output
[quoted text clipped - 5 lines]
>> file, the result is returned as the file name and not the file contents!!
>> _BodyFilename is defined by Path.GetTempFileName()
Som Nath Shukla - 28 Sep 2007 14:05 GMT
every time u write Path.GetTemFilename() generates a new temporary file.
send me ur full code .

> The file has data in it which was written "earlier". I just generated the
> temp file using gettempfilename.
[quoted text clipped - 11 lines]
> >> file, the result is returned as the file name and not the file contents!!
> >> _BodyFilename is defined by Path.GetTempFileName()
Som Nath Shukla - 28 Sep 2007 14:15 GMT
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

> The file has data in it which was written "earlier". I just generated the
> temp file using gettempfilename.
[quoted text clipped - 11 lines]
> >> file, the result is returned as the file name and not the file contents!!
> >> _BodyFilename is defined by Path.GetTempFileName()
John Duval - 28 Sep 2007 13:54 GMT
> I can't see what Ive done wrong with the following, would someone help
> please.
[quoted text clipped - 19 lines]
>
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.