Word object
-
using Office = Microsoft.Office.Core; using Word = Microsoft.Office.Interop.Word; --Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown) Enumerators in .NET: See how to customise foreach loops with C#
i typed the full path but the code doesn't compile at all this code is: private void btn_create_Click(object sender, System.EventArgs e) { Microsoft.Office.Interop.Word.Application newApp = new Microsoft.Office.Interop.Word.Application(); l_status.Text+="object instantiated\n"; object Source="c:\\abc\\dat.doc"; object Target="c:\\abc\\Target.rtf"; object Unknown =Type.Missing; // Source document open here // Additional Parameters are not known so that are // set as a missing type newApp.Documents.Open(ref Source,ref Unknown, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown,ref Unknown,ref Unknown); l_status.Text+="file opened\n"; // Specifying the format in which you want the output file object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatRTF; l_status.Text+="new format created"; //Changing the format of the document newApp.ActiveDocument.SaveAs(ref Target,ref format, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown); l_status.Text+="new file saved \n"; // for closing the application newApp.Quit(ref Unknown,ref Unknown,ref Unknown); l_status.Text+="object closed \n"; } =============================================== the error message is : An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in code_container.exe Additional information: The server threw an exception.
-
i typed the full path but the code doesn't compile at all this code is: private void btn_create_Click(object sender, System.EventArgs e) { Microsoft.Office.Interop.Word.Application newApp = new Microsoft.Office.Interop.Word.Application(); l_status.Text+="object instantiated\n"; object Source="c:\\abc\\dat.doc"; object Target="c:\\abc\\Target.rtf"; object Unknown =Type.Missing; // Source document open here // Additional Parameters are not known so that are // set as a missing type newApp.Documents.Open(ref Source,ref Unknown, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown,ref Unknown,ref Unknown); l_status.Text+="file opened\n"; // Specifying the format in which you want the output file object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatRTF; l_status.Text+="new format created"; //Changing the format of the document newApp.ActiveDocument.SaveAs(ref Target,ref format, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown); l_status.Text+="new file saved \n"; // for closing the application newApp.Quit(ref Unknown,ref Unknown,ref Unknown); l_status.Text+="object closed \n"; } =============================================== the error message is : An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in code_container.exe Additional information: The server threw an exception.
hazzem elrefai wrote: An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in code_container.exe Indicates that the code has compiled. You have a runtime error. What line did this happen on? --Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown) Enumerators in .NET: See how to customise foreach loops with C#
-
hazzem elrefai wrote: An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in code_container.exe Indicates that the code has compiled. You have a runtime error. What line did this happen on? --Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown) Enumerators in .NET: See how to customise foreach loops with C#
the error in the main finction line : and i couldn't get any meaningful data from this erorr static void Main() { Application.Run(new MainForm()); }
-
hazzem elrefai wrote: An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in code_container.exe Indicates that the code has compiled. You have a runtime error. What line did this happen on? --Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown) Enumerators in .NET: See how to customise foreach loops with C#
the erorr message say: the server threw an exception and nothing more.
-
the error in the main finction line : and i couldn't get any meaningful data from this erorr static void Main() { Application.Run(new MainForm()); }
I suspect this is where the exception was CAUGHT. Not where it was generated/thrown.
static void Main()
{
try
{
Application.Run(new MainForm());
}
catch(Exception e)
{
Debug.WriteLine(e.Message);
Debug.WriteLine(e.StackTrace);
}
}Will write to the output the location that the error was generated. This will help with solving the problem. --Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown) Enumerators in .NET: See how to customise foreach loops with C#
-
I suspect this is where the exception was CAUGHT. Not where it was generated/thrown.
static void Main()
{
try
{
Application.Run(new MainForm());
}
catch(Exception e)
{
Debug.WriteLine(e.Message);
Debug.WriteLine(e.StackTrace);
}
}Will write to the output the location that the error was generated. This will help with solving the problem. --Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown) Enumerators in .NET: See how to customise foreach loops with C#
i used try catch statements and the erorr is comming from this line: newApp.Documents.Open(ref Source,ref Unknown, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown,ref Unknown,ref Unknown); plz keep with me and this will be apreciated thnx another time
-
I suspect this is where the exception was CAUGHT. Not where it was generated/thrown.
static void Main()
{
try
{
Application.Run(new MainForm());
}
catch(Exception e)
{
Debug.WriteLine(e.Message);
Debug.WriteLine(e.StackTrace);
}
}Will write to the output the location that the error was generated. This will help with solving the problem. --Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown) Enumerators in .NET: See how to customise foreach loops with C#
Colin, note that putting a try-catch around
Application.Run
only works when an exception causes the application message pump to terminate. This is usually not the case. The try-catch should be as local to the problem as possible (like in the original poster's code to create the Word app and open the document). You can also handle theAppDomain.UnhandledException
event.-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
-
Colin, note that putting a try-catch around
Application.Run
only works when an exception causes the application message pump to terminate. This is usually not the case. The try-catch should be as local to the problem as possible (like in the original poster's code to create the Word app and open the document). You can also handle theAppDomain.UnhandledException
event.-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
Heath Stewart wrote: Colin, note that putting a try-catch around Application.Run only works when an exception causes the application message pump to terminate True, like happened here. I realise that the try...catch would be better placed else where but trying to help quickly I figured it was easiest to put round the
Application.Run
. --Colin Mackay--"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown) Enumerators in .NET: See how to customise foreach loops with C#
-
Heath Stewart wrote: Colin, note that putting a try-catch around Application.Run only works when an exception causes the application message pump to terminate True, like happened here. I realise that the try...catch would be better placed else where but trying to help quickly I figured it was easiest to put round the
Application.Run
. --Colin Mackay--"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown) Enumerators in .NET: See how to customise foreach loops with C#
iam so confised now,coz i can not run my application yet and i do not know what is the problem exactly.
-
iam so confised now,coz i can not run my application yet and i do not know what is the problem exactly.
Well, it looks like your code was copied from the documentation. So I don't see much difference between that and MSDN. Are you using a WordProject? --Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown) Enumerators in .NET: See how to customise foreach loops with C#
-
Well, it looks like your code was copied from the documentation. So I don't see much difference between that and MSDN. Are you using a WordProject? --Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown) Enumerators in .NET: See how to customise foreach loops with C#
i do not know what is word project exactly but if it is wizard in vs.net,then i do not use it and it doesn't there iam using vs.net2003 profissional thanx
-
i do not know what is word project exactly but if it is wizard in vs.net,then i do not use it and it doesn't there iam using vs.net2003 profissional thanx
I'm using VS2003 and Office 2003 (So it might be an office thing) Anyway - I've emailed you the skeleton of the WordProject - it might provide clues to help with your problem. (Its easy for me because it does all the hard work getting everything integrated - You may have to change the project properties because the startup command line may be different in your case) --Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown) Enumerators in .NET: See how to customise foreach loops with C#
-
I'm using VS2003 and Office 2003 (So it might be an office thing) Anyway - I've emailed you the skeleton of the WordProject - it might provide clues to help with your problem. (Its easy for me because it does all the hard work getting everything integrated - You may have to change the project properties because the startup command line may be different in your case) --Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown) Enumerators in .NET: See how to customise foreach loops with C#
thank u so so so much and sorry coz i have to go know and c u after little hours