setup file is not working fine on client machines - winforms

I created a windows form application and my application will read the data from the two xml files in which these files are stored in application bin\debugger folder ,these files will change while running the application and also my form is using the windows media player and some other xml files which are stored in the system drives.
I created a setup file like below procedure
right click on Solution > Add > New Project >setup name
in Application folder I added two xml files and while adding the primary output of application i got a pop up box saying that it depends on the wmp.dll i added that one also.
created a shortcut for primary output ,cut and pasted into user's desktop and next in User Program i created a new folder in that folder i created a shortcut for primary output of an application and named as a setup file next I builded the setup file and after wards and I installed the setup in developed code machine its working fine but when i install the setup file on another computer it is not working please tell me what will be the reason, i'm struggling for this since from 3 days
Note: I added the system drives files in that locations before application running on the client computer
public partial class Form1 : Form
{
XmlDocument SysDetails = new XmlDocument();
XmlDocument UsrDetails = new XmlDocument();
Public Form()
{
string filePath1 = Application.StartupPath;
string org1 = filePath1+ "\\UserFirstDetails.xml";
UsrDetails.Load(org1);
XmlNode NdeFirst= UsrDetails.SelectSingleNode("UserFirstDetails/IsFirstTime");
FirstTime = NdeFirst.InnerText;
if (FirstTime == "True")
{
NdeFirst.InnerText = "False";
XmlNode productnum = UsrDetails.SelectSingleNode("UserFirstDetails/ProductOrderNum");
productnum.InnerText = ProductNo;
UsrDetails.Save(org1);//here i'm getting an exception ,please help me
in setup project it is points to C:\Program Files\Default Company Name\Setup Project, How to make C:\Project Files folder ReadOnly attribute to false
}
}
}

Based on the code sample and the Access Denied error...
Programs cannot write to the ProgramFiles directory unless they are elevated to admin level. So there are two solutions:
There are directories for user data, such as Application Data Folder, User's Application Data Folder etc, and that's where data files should be created and updated, and installed to, not the Program Files directory.
If your program does a bunch of things that require admin privilege and you decide that users need to have admin privilege to run it, then give it an elevation manifest so there will be an elevation dialog when the program starts up.
There's an article here:
http://www.codeproject.com/Articles/17968/Making-Your-Application-UAC-Aware

Related

Webview2 in Windows Forms application can't write to userdatafolder but the application can write other files to the folder

I'm creating a webview2 with the code below in a Windows Forms Application. It works on one computer, but on another it can only write the webview2cache folder but no contents. The application user has full permissions and the application is writing other folders and files on that computer in the same location with no issues.
Does webview2 need some kind of special permissions?
string userfolderpath = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal)
.FilePath.Replace("user.config", "") + "webview2cache\\";
Directory.CreateDirectory(userfolderpath);
var env = await CoreWebView2Environment.CreateAsync(#"webview2", userfolderpath);
await webview2.EnsureCoreWebView2Async(env);

Eclipse Che failing to open file on restart

I have started using Eclipse che to develop a app using CakePHP. However when I exit and come back to the project it comes up with an error
The file app/config/database.php could not be opened
and i can no longer see the file in the directory structure. Creating a file of the same name does not produce an error.
All this file contains is a class with an array containing the infromation about connecting to a database eg ip, username and password.

Build approach for creating ClickOnce packages for multiple environments

Here is my scenario:
I have a WPF application which I am delivering via ClickOnce. The application has multiple environments for multiple clients (currently 9 but expecting to double that in the near future).
The process I currently use is (basically):
Token replace parts of the app.config
Token replace parts of the WiX file used in the generation of the MSI installer (including the signing certificate and thumbprint)
Build the solution
Create a Client/Environment specific installer
Repeat for each client/environment combination
This has the benefit of meaning that to install the application it is a simple case of running the required installer. However, the downside is that if (when) I need to create a new environment, I have to re-run the whole build process with a new set of configuration parameters.
How can I make this all better?
My latest thought is that I split out my build process to just create the binaries. Then have a separate packaging process that that pulled in the appropriate binaries, patched configs, (re)signed manifests using MAGE etc.
This will have the continued benefit of "build once, deploy multiple times", whilst ensuring that if new environments were required they could be repackaged without rebuilding the binaries.
Does this sound like a sensible approach?
Does anyone have any guidance for such a scenario?
Thanks
We had a similar scenario, with a WPF ClickOnce application used in multiple environments, where the only thing in app.config is a connectionstring.
To get around the fact that you can not change the configuration file within the clickonce package without having a build process building one package for each client/environment we came up with a solution that lets you place an app.config file in the server deployment folder and let the application access that at runtime.
To do that, we created a static class that initializes in app.xaml.cs OnStartup event.
public static class DbConnectionString
{
public static string ConnectionString { get; private set; }
public static string ActivationPath { get; private set; }
public static void Init()
{
string dbContext = "myDbContext";
string configFile = "App.config";
ConnectionString = "";
ActivationPath = "";
ActivationArguments actArg = AppDomain.CurrentDomain.SetupInformation.ActivationArguments;
if (actArg != null)
{
if (actArg.ActivationData != null)
{
try
{
var actData = actArg.ActivationData[0];
var activationPath = Path.GetDirectoryName(new Uri(actData).LocalPath);
var map = new System.Configuration.ExeConfigurationFileMap();
map.ExeConfigFilename = Path.Combine(activationPath, configFile);
var config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
var connectionStringSection = config.ConnectionStrings;
ConnectionString = connectionStringSection.ConnectionStrings[dbContext].ConnectionString;
ActivationPath = activationPath;
}
catch (Exception)
{
ConnectionString = "";
ActivationPath = "";
}
}
}
}
}
In the Project settings under Publish/Options/Manifests tick the "Allow URL parameters to be passed to application"
I then use the ConnectionString property of the static class where I need a connection string. It will not be set unless you deploy the app as online only, so we default to the app.config within the package for dev/testing.
It is a bit convoluted, but works well, and you only have to publish your app once and provide an app.config for each installation that does not change between builds.
It also sets the property ActivationPath which is the path to the clickonce server install directory.
That sounds like a step in the right direction, and is similar to what I've been doing for a WPF application for a couple of years, and it has worked well.
We build the solution with Team City and then have multiple after build steps which handle the ClickOnce publishing, one step for each configuration. Each configuration involves kicking off an MSBuild file which uses Mage.exe. It copies the solution output files to a temporary directory and then performs numerous replacements on files such as the App.config and runs various custom MSBuild tasks.
The MSBuild project file contains base settings and environment overrides for things like the ClickOnce download URL. We also have to do some hacky replacements on the generated manifest itself (and then re-sign it) for things like marking particular files as data, or not.

Silverlight 4 FileInfo.OpenRead method is working on any folder without elevated permissions

I have a Silverlight 4 application running inside the browser without elevated permission and in it I have an upload files functionality section where an OpenFileDialog window appear and you can select the files you want to upload and save the files into the database.
The problem is that the application can actually Access files outside the user's profile folders which is not allowed by the silverlight security policy.
private Asset ReadAsset(FileInfo fileInfo)
{
byte[] fileBuffer;
using (FileStream fileStream = fileInfo.OpenRead()) //This line works from any location
{
using (BinaryReader binaryReader = new BinaryReader(fileStream))
{
fileBuffer = binaryReader.ReadBytes((int)fileStream.Length);
binaryReader.Close();
}
fileStream.Close();
}
DirectoryInfo di = fileInfo.Directory; //This line doesn't work
}
This actually READ the files no matter the location (I could even read a file on system32 folder) and I have no means to get "My Documents" or "Documents" folder because even.
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
Is not working. So in short. I can read the bytes from any file on any location which silverlight apps running on browsers are not suppose to do.
Any help will be appreciated.
I think what you seem to be concerned about is that via OpenFileDialog any file can be read regardless of its location in the client file system.
This fine and normal. The OOB with trust restrictions only apply to unsolicited access. That is access to the file system without direct and explicit interaction by the user.
In the case of OpenFileDialog the user has explicit specified what file(s) to select and users are free to select any files they wish. This is true even for an standard inbrowser app.

System.IO.FileInfo throwing access is denied exception to a local file

I created a sample Silverlight Web project
and I am getting 'Access is denied' when I do this:
string fileName = "map.gif";
FileInfo fileInfo = new FileInfo(fileName);
How can I give the web project access to this folder/file?
I added the image into my project, really drawing a blank here....
You don't access files you've placed in the project using the FileInfo object. Instead you create a Uri to access it.
Its not clear from your question which project you've place the file in. If you have placed it in the Silverlight project then it ought to end up as content in the Xap. In which case you can acquire StreamResourceInfo for it using:-
StreamResourceInfo gifContentInfo = Application.GetResourceStream(new Uri("map.gif", UriKind.Relative));
Now you can get to the file content with:-
Stream gifStream = gifContentInfo.Stream;
On the other hand if you have placed the file in the web project it will be a standard static file in the web site. Hence you will need to do the typical WebClient download to fetch it.
I take it you are going to this trouble because its a Gif file; you are aware that they are not supported as an image.
You can't use the filesystem in Silverlight outside of Isolated Storage
you need to give file access to the asp.net user
check this out:
http://www.codeproject.com/KB/aspnet/Ahmed_Kader.aspx
Or use the special folder which asp.net provides for you
... APP_DATA
that should have the rights you need...
I am assuming you are trying to access a file in the local filesystem.
If so, you cannot access files like that. Silverlight does not have the access priveleges u expect. If you want to add a file to your Silverlight Application at runtime. You will need to have Silverlight 4, running Out of the Browser with Elevated priveleges. There are certain limitations to this too. You can only access files in Special Folders like My Documents, Pictures, Music etc. For more info about access files this way. You can look at John's tutorials on Silverlight 4 elevated priveleges in Channel 9 MSDN.
I would doubt your FileInfo usage too. Here is a sample code to get file data using a simple drag and drop feature.
private void list_Drop(object sender, DragEventArgs e)
{
FileInfo[] files = (FileInfo[])e.Data.GetData(DataFormats.FileDrop);
for(int i=0;i<files.Length;i++)
textblock.Text += files[i].Name;
}
You can get the properties of the file such as "Name". You wil not hit any access denied errors. You cannot access properties like "DirectoryName", "FullName" etc. The reason being they are declared as SecurityCritical properties for Security reasons. The advantage of elevated permissions is that you can get to local file system (special folders) to access the FullName and DirectoryName properties without any exceptions.
Hope this helps

Resources