none
Microsoft.Office.Interop.Excel.WorkbookClass.SaveAs and RPC_E_SERVERFAULT RRS feed

  • Question

  • Hello,

    I'm using following C# Code

    object tm = Type.Missing;
    string tmpXlsxFileName = Path.GetTempFileName();
    tmpXlsxFileName = tmpXlsxFileName.Substring(0, tmpXlsxFileName.Length - 3) + "xlsx";
    
    string tmpfile = Path.GetTempFileName();
                       
    ExcelHelper.oExcelApp.ActiveWorkbook.SaveCopyAs(tmpfile);
    Excel.Workbook tmpBOOK = ExcelHelper.oExcelApp.Workbooks.Add(tmpfile);
    
    tmpBOOK.SaveAs(tmpXlsxFileName, (object)51, tm, tm, tm, tm,
     Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive,<br/> Microsoft.Office.Interop.Excel.XlSaveConflictResolution.xlLocalSessionChanges,
     tm, tm, tm, tm);
    


    If environment variable 'Temp' is set to

    "C:\Dokumente und Einstellungen\pyemyem\Lokale Einstellungen\Temp\"

    then I get Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT) when excecuting line with saveas.

    If 'Temp' is set to "C:\temp" then saveas works.

    Any ideas ?

     

      Hendrik

     

     

     

     

    Thursday, October 20, 2011 1:17 PM

All replies

  • Pasted code again
    object tm = Type.Missing;
    string tmpXlsxFileName = Path.GetTempFileName();
    tmpXlsxFileName = tmpXlsxFileName.Substring(0, tmpXlsxFileName.Length - 3) + "xlsx";
    
    string tmpfile = Path.GetTempFileName();
                       
    ExcelHelper.oExcelApp.ActiveWorkbook.SaveCopyAs(tmpfile);
    Excel.Workbook tmpBOOK = ExcelHelper.oExcelApp.Workbooks.Add(tmpfile);
    
    tmpBOOK.SaveAs(tmpXlsxFileName, (object)51, tm, tm, tm, tm,
    Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive,
    Microsoft.Office.Interop.Excel.XlSaveConflictResolution.xlLocalSessionChanges,
     tm, tm, tm, tm);
    
    
    

    Thursday, October 20, 2011 1:18 PM
  • Hi,

    Thanks for your post.

    Would you like to tell me why you need to change the path of temporary folder? What your code suppose to do?

    The default path of temporary folder is "C:\Users\UserName\AppData\Local\Temp", and it works fine when running the code above.

    I look forward to hearing of you.


    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, October 21, 2011 7:07 AM
    Moderator
  • Hello,

    on a german Windows XP the default temp path is a little bit different.

    %USERPROFILE%\Lokale Einstellungen\Temp

    USERPROFILE=C:\Dokumente und Einstellungen\<username>.

     

    So the the default temp path contains spaces on a german Windows XP.

    With the deafult temp path I get RPC_E_SERVERFAULT , but when I change Temp to a directory without spaces I don't get this error.

    The code should save a copy of the activeworkbook to a temporary file in xlsx format.

    It looks like this only happens with Excel 2003 and installed xlsx converter.

     

    with best regards

      Hendrik

     

    Friday, October 21, 2011 7:55 AM