Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 31st, 2006, 01:31 PM
Authorized User
 
Join Date: Jun 2003
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default Created RTF when try to open RTF, got an error

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.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading an RTF File apoorva_ca C# 2005 1 January 10th, 2008 11:34 AM
C# RTF To XML nagajeya ASP.NET 1.0 and 1.1 Professional 5 December 11th, 2007 12:14 PM
PDF and RTF from XML rajatake XML 2 March 28th, 2007 12:35 PM
XSLT to RTF bonekrusher XSLT 4 August 13th, 2006 03:07 PM
hyperlinks of rtf files geetabajpai VB How-To 1 October 13th, 2005 04:44 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.