How can I read a file present at the installation folder of my optional package - msix

I have added a file as part of an optional package, which is consumed by a main C# application. When I try to read that file which is present at
C:\Program Files\WindowsApps\<Package_Name_Etc>\search.config
using (Stream reader = new FileStream(Path.Combine(_directory,"search.config"), FileMode.Open))
I get an error of System.UnauthorizedAccessException: 'Access to the path 'C:\Program Files\WindowsApps\<Package_Name_Etc>\search.config' is denied.'
I fail to understand why the code of optional package doesn't have access to this file.

It might fail because you are using FileMode.Open, which has by default read/write access.
Try setting FileAccess to read.
The files from the installation folder of an MSIX package are read-only. Apps that try to load them while requesting write permissions will fail. If you want to write something in the config file you should create a copy of the file in the AppData folder, the first time your application is launched, and edit that copy of the file.

Related

Jenkins Error "Microsoft Excel cannot access the file"

I am using jenkins to run a .bat file that is in location
C:\Users\foo\Desktop\xxx.bat
which internally
copies from another machine an excel
calls a vbs script found in D:
D:\foo\Newtask.vbs
that opens a file:
C:\Users\foo\Desktop\xxx\xxx\xxx\New.xlsm
The error I am getting is
For the first excel: The system cannot find the path specified
For the second New.xlsm:
D:\foo\Newtask.vbs(14, 1) Microsoft Excel: Microsoft Excel cannot access the file 'C:\Users\foo\Desktop\xxx\xxx\xxx\New.xlsm'. There are several possible reasons:
The file name or path does not exist.
The file is being used by another program.
The workbook you are trying to save has the same name as a currently open workbook
I find it odd that jenkins can access and run .bat in foo user's directory while it cannot find C:\Users\foo\Desktop\xxx\xxx\xxx\New.xlsm --> I checked it exists.
When running the .bat manually i have no problem.
Any ideas?
I had the same issue. Solution from this page worked https://techcommunity.microsoft.com/t5/sql-server-support-blog/error-8216-microsoft-office-excel-cannot-access-the-file-8217/ba-p/317477
...x64: Create the following directory:
C:\Windows\SysWOW64\config\systemprofile\Desktop
x86: Create the following directory:
C:\Windows\System32\config\systemprofile\Desktop...

Cannot compile the generated code. Please inspect the generated code via this exception's SourceCode property

I installed my private application which makes use of the Desktop Bridge and Dev Express XAF Winforms, from the Windows Store.
Then I uninstalled it using powershell
Remove-AppxPackage -Package *jobtalk*
Now when I try to reinstall from the store I get
Cannot compile the generated code. Please inspect the generated code via this exception's SourceCode property. The following errors occurred:
(0, 0): Error generating Win32 resource: Access is denied.
(0, 0): Unable to delete temporary file 'c:\Program Files\WindowsApps\jobtalk.jobtalk_1.0.1.0_neutral__8kpaqbvntb9aj\SBD.JobTalk.Workflow.Win\CSC88B14BFB7D314F00B0D1BB57EFD11.TMP' used for default Win32 resource -- The system cannot find the file specified.
[Update]
I think I need to install as administrator somehow.
The problem and solution are described at http://blog.delegate.at/
In order to contain app state, the bridge attempts to capture changes the app makes to AppData. All write to the user's AppData folder (e.g., C:\Users\user_name\AppData), including create, delete, and update, are copied on write to a private per-user, per-app location.

SSIS not writing file while executing from different user

I have developed SSIS package to export data to excel file. below are the steps executed by the package
1.Send mail of starting package
2.Copy excel Template to Source folder ( This is Temporary file )
3. Retrieve data (In this step we are retrieve data from 6-7 tables)
4.create folder structure to export i.e First check folder for year and month if not exist dot create
5.Copy the source folder file (Step2) to above create folder.
The problem here is when I deploy and execute package through my account its run perfectly. But same package with same setting if I run through different account its not writing file ie. Its copies source file at the end. but in execution it shows its executed successfully at the start. click for excution Report
Based on your description, please check your account permission for the one you failed to run the package. The account to execute to package should have the full permission to read from database and also make sure that account could visit, read and write to windows directory.

How to save files in temp directory for any platform?

I have a Grails application in which I generate PDF/Excel files in a folder.
My problem is, everytime I need to change the directory path through code when I test or run the code on different machines like Windows, Linux, Mac.
So what is the generic path, which will be applicable for any/all platforms as the default temp directory, so that I won't need to manually set path for the directory while running code on different machines/platforms.
The temp directory is available via
String tempDir = System.getProperty('java.io.tmpdir')
To create temp files in the default location for the OS you can use File.createTempFile(prefix,suffix)

LuaEdit can't find module when Lua files all in the same folder

I downloaded LuaEdit to use as an IDE and debug tool however I'm having trouble using it for even the simplest things. I've created a solution with 2 files in it, all of which are stored in the same folder. My files are as follows:
--startup.lua
require("foo")
test("Testing", "testing", "one, two, three")
--foo.lua
foo = {}
print("In foo.lua")
function test(a,b,c) print(a,b,c) end
This works fine when in my C++ compiler when accessed through some embed code, however when I attempt to use the same code in LuaEdit, it crashes on line 3 require("foo") with an error stating:
module 'foo' not found:
no field package.preload['foo']
no file 'C:\Program Files (x86)\LuaEdit 2010\lua\foo.lua'
no file 'C:\Program Files (x86)\LuaEdit 2010\lua\foo\init.lua'
no file 'C:\Program Files (x86)\LuaEdit 2010\foo.lua'
no file 'C:\Program Files (x86)\LuaEdit 2010\foo\init.lua'
no file '.\foo.lua'
no file 'C:\Program Files (x86)\LuaEdit 2010\foo.dll'
no file 'C:\Program Files (x86)\LuaEdit 2010\loadall.dll'
no file '.\battle.dll'
I have also tried creating these files prior to adding them to a solution and still get the same error. Is there some setting I'm missing? It would be great to have an IDE/debugger but it's useless to me if it can't run linked functions.
The issue is probably that your Lua files are not on the path in package.path (for C files this is package.cpath).
My guess is that the LuaEdit program is not launched in the directory you have your files in, and hence does not have a match for eg .\foo.lua.
You have 3 simple solutions to this (from dumb to smarter):
Find out what path LuaEdit considers as ./ and put your files there.
Open up a terminal in the right directory (the one containing your files), and run LuaEdit from there.
Add the path the files are on to package.path and package.cpath before doing any require's
You may need to put:
lua
package.path = package.path..";c:/path/to/my/files/?.lua"
at the beginning of your files before any require (as jpjacobs indicated). I couldn't find any way to provide this from LuaEdit itself. It appears it runs the script using its full path, but keeps its current dir set to whatever it was when the IDE was started. If you run LuaEdit using full path from your application folder, it should work fine even without package.path changes.
While the IDE itself works fine with its own modules/libraries, it doesn't mean it makes them available to the application it runs.
(shameless plug) If you're still not happy with LuaEdit, I'd offer ZeroBrane Studio Lua IDE as an alternative, It's based on the same wxLua framework, but provides a bit more functionality and doesn't have this particular issue you're facing. It also supports remote debugging, so you should be able to debug your Lua scripts directly from your application.

Resources