0
votes

I've been trying to save my new word document using SaveAs2 but couldn't resolve the error. This is my code to save file

                word.Document newdocument = new word.Document();
                newdocument = oword.Documents.Add(ref missing, ref missing, ref missing, ref missing);
                word.Range rng = newdocument.Range(0, 0);
                rng.Text = "start:\r\r" + content.Value.ToString();
                rng.Text += "\rend:\r\r";
                rng.Text += AnswerDictionary[content.Key.ToString()];
                start = newdocument.Content.Start;
                end = newdocument.Content.End;
                range = newdocument.Range(ref start, ref end);
                range.Select();
                range.Font.Size = 11;
                range.Font.Name = "Georgia";
                rng.ParagraphFormat.Alignment = word.WdParagraphAlignment.wdAlignParagraphJustify;
                rng.ParagraphFormat.LineSpacingRule = word.WdLineSpacing.wdLineSpaceDouble;
                rng.ParagraphFormat.SpaceAfter = 0;
                rng.ParagraphFormat.SpaceBefore = 0;
                newfilename = @"C:\4PT\Output\" + content.Key.ToString() + ".docx";
                //newdocument.SaveAs2(ref newfilename, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
                newdocument.SaveAs2(ref newfilename);

I am getting this error

Exception:Thrown: "The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))" (System.Runtime.InteropServices.COMException) A System.Runtime.InteropServices.COMException was thrown: "The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))" Time: 4/22/2018 11:39:12 PM Thread:[9556]

Kindly tell me what i'm doing wrong here?

1
I am unable to save my document by any method.Ayyaz Ali Furqan
I am using .Net Framework 4.5Ayyaz Ali Furqan
The code triggered a hard crash inside the Word process. Consider setting word.Visible = true and with some luck you'll now see a decent message from Word itself. If not then do try this on another machine.Hans Passant
Please post code we can use to reproduce the problem. The code you provide is not complete, so we can't guess where your problem might be. Provide static strings instead of variables with information you're using that causes the crash. FWIW when you use method(ref info) What you pass with ref should be of datatype object - but that would throw a different error, not crash...Cindy Meister

1 Answers

0
votes

Okay, i've got the problem. Saveas2 was only for Microsoft office 2010 and the solution to this problem was only to use Saveas instead of Saveas2.