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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Created RTF when try to open RTF, got an error

Status
Not open for further replies.

not24

Programmer
Feb 25, 2002
68
US
After create RTF, try to open, got an error "Word experienced an error trying to open the file".

I have C# class that generate RTF code and savve to RTF by stores RTF code in StringBuilder and using the following code to write text as a file:

StreamWriter SW = null;
try
{
SW = File.CreateText(filepath);
SW.WriteLine(rtfCode); //string pass from StringBuilder
}
catch (Exception ex)
{
throw ex;
}
finally
{
if(SW != null)
{
SW.Flush();
SW.Close();
}
GC.Collect();
GC.WaitForPendingFinalizers();
}

The problem is I have a class to open RTF file w/ MS Word to open RTF file right away after save, sometime I'd get this error:

"Word experienced an error trying to open the file.
Try these suggestions.
* Check the file permissions for the document or drive.
* Make sure there is sufficient free memory and disk space.
* Open the file with the Text Recovery converter. "

But when I open that folder and double click same file, I can open it just fine. I did some search on google but not found much.

1. Is that mean file still in use even after I run "GC.Collect();..." command?
2. If yes, how can I check file in use or clear it from memory?
3. The RTF file need to be open right after save. Is there anyway I can work around this?

Any suggestion is welcome. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top