Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Problem opening file from an application
Guest
#1 Posted : Monday, March 12, 2012 4:43:51 AM(UTC)
Groups:
Joined: 11/1/2005(UTC)
Posts: 278

Hi,

we have a problem with calling interop library from webservice. The webservice uses other dll where is called function 'Open'(mentioned below), if this dll is called from another exe then excel file is normally opened. Before than function 'Open' is called it's ensured the file does exist and it is not read-only. If the exe is called from Cassini we get the same error.


Cassini returns this kind of error:
Error Opening File 'D:\xls\Mappe1.xlsx'. Detail: Microsoft Office Excel kann auf die Datei 'D:\xls\Mappe1.xlsx' nicht zugreifen. Dies kann mehrere Gründe haben:

• Der Name des Dokuments oder der Pfad ist nicht vorhanden. (EN: doc name or path is not available)
• Das Dokument wird von einem anderen Programm verwendet. (EN: doc is used by another appl.)
• Der Name der Arbeitsmappe, die gespeichert werden soll, ist identisch zu dem Namen eines anderen Dokuments, welches schreibgeschützt ist. (EN: read-only problem)


public void Open(string fileName)
{
try
{
Worbooks.Add(App.Workbooks.Open(fileName,
true,
false,
System.Type.Missing,
System.Type.Missing,
System.Type.Missing,
System.Type.Missing,
System.Type.Missing,
System.Type.Missing,
false,
System.Type.Missing,
System.Type.Missing,
false,
System.Type.Missing,
System.Type.Missing));
_OpenFileName = fileName;
}
catch (Exception err)
{
throw new Exception(
String.Format(CultureInfo.InvariantCulture, "Error Opening File '{0}'. Detail: {1}", fileName, err.Message), err);
}
}


env.:
*UltiDev Web Server Pro Build 15 (v. 2.0.15) - running in 32 bit mode
*OS Windows Server 2008 R2 x64
*MS Office 2007 sp1 32b (Microsoft.Office.Interop.Excel.dll 11.0.5530.0, *Microsoft.Vbe.Interop.dll 11.0.5530.0)
*full local admin


Similar thread http://ultidev.com/Forum...Problem-with-excel.aspx didn't fix our troubles.
Thanks a lot for feedback.
Ultidev Team
#2 Posted : Monday, March 12, 2012 9:29:33 AM(UTC)
Ultidev Team

Groups: Administration
Joined: 11/3/2005(UTC)
Posts: 2,253

Thanks: 28 times
Was thanked: 60 time(s) in 59 post(s)
Hi there!

Thank you for the detailed problem description.

The most likely cause of the issue is access rights to the file/folder in question.

Unlike regular Windows programs, which run as logged in user and have the same access privileges, hosted web applications are started by a windows service and have different access rights context. When you register an application with UWS, the application will run either as a NETWORK SERVICE or a LOCAL SYSTEM user. We suspect you run your application in a host process running under NETWORK SERVICE account. NETWORK SERVICE is more secure, which makes it better suitable for Internet-facing applications, but also more restricted, often not having access rights to many parts of the system.

To work around the problem, you could put the files you are trying to open under App_Data folder, which UWS makes accessible to NETWORK SERVICE user when application with App_Data gets registered. You could also try to re-register the application under LOCAL SYSTEM, but that needs to be done only with good understanding of security risks of your environment, because hacked application running under LOCAL SYSTEM exposes most of the system.

Please let us know if this information was helpful.

Best regards,
UltiDev Team.
Please donate at http://www.ultidev.com/products/Donate.aspx to help us improve our products.
Guest
#3 Posted : Tuesday, March 13, 2012 4:08:21 AM(UTC)
Groups:
Joined: 11/1/2005(UTC)
Posts: 278

unfortunately a problem is probably somewhere else because before function 'Open' is checked an existence of file and rights to read


_fs = File.OpenRead(excelFilePath);
if (_fs != null)
_fs.Close();
else
{
retVal.ErrorCode = 2;
retVal.ErrorText = string.Format("NIU-GetDataFromExcel: Input Excel file {0} not found or no access", excelFilePath);
return retVal;
}
Ultidev Team
#4 Posted : Tuesday, March 13, 2012 11:00:45 AM(UTC)
Ultidev Team

Groups: Administration
Joined: 11/3/2005(UTC)
Posts: 2,253

Thanks: 28 times
Was thanked: 60 time(s) in 59 post(s)
Hi!

We still suggest trying our proposed fixes, because not having read-only flag on the file is not equal to being able to read it.

Best regards,
UltiDev Team.
Please donate at http://www.ultidev.com/products/Donate.aspx to help us improve our products.
Guest
#5 Posted : Friday, March 16, 2012 4:41:57 AM(UTC)
Groups:
Joined: 11/1/2005(UTC)
Posts: 278

Hi again,

it runs under LOCAL SYSTEM user.
Ultidev Team
#6 Posted : Friday, March 16, 2012 9:12:29 AM(UTC)
Ultidev Team

Groups: Administration
Joined: 11/3/2005(UTC)
Posts: 2,253

Thanks: 28 times
Was thanked: 60 time(s) in 59 post(s)
Hi there.

This is an issue of application host process running under restricted NETWORK SERVICE account. NETWORK SERVICE is chosen as default because it is more secure and therefore is safer for hosting Internet-facing applications. LOCAL SYSTEM can be used with caution, if your application runs in a controlled, low-threat environment.

If you chose to run the application under a NETWORK SERVICE, which, unlike LOCAL SYSTEM, does not have access to every folder on disk, you may do the following:

  • Best practice is to put files in App_Data folder. UWS grants NETWORK SERVICE access rights to it when an application gets registered.
  • Grant NETWORK SERVICE user access to folder/files in question.
  • Move the logic that needs higher privileges into out-of-process ServicedComponent, or into a Windows Service accessed via .NET Remoting. Each of them would run in a different process, as any user that has access to the file in question.


Best regards,
UltiDev Team.

P.S. In order to be able to attach files to a post, please create forum account and log in.
Please donate at http://www.ultidev.com/products/Donate.aspx to help us improve our products.
Rss Feed  Atom Feed
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You can vote in polls in this forum.