I'm developing a Windows Form application under Windows XP. I've created a Class Library that is accessed by the user application in order to create PDF documents using PdfSharp and MigraDoc libraries.
My problem starts when I try to add a bitmap to the PDF. I have the image stored in the resources, and due MigraDoc features, I firstly need to save the file on the disk in order to do that, as you can see in the next lines:
string logoTemp = Directory.GetCurrentDirectory().ToString() + "\\imagename.png";
if (!File.Exists(logoTemp))
((Bitmap)Properties.Resources.imagename).Save(logoTemp, ImageFormat.Png);
paragraph.AddImage(logoTemp);
It works fine on my computer and also on a 32 bits Windows 7, but it gets throw an exception on 64 bits Windows 7, as showed in the next screenshot:
This error is solved if I run the application as Administrator, but that is not acceptable.
Any ideas?
Put your code in a try { } catch() {} block and see what exception it throws using a debugger.
Related
I have a problem with my WPF application (a simple clicker game). I've just made a deployment/created a setup project using Microsoft Visual Studio Installer Projects extension for Visual Studio. Everything seemed to work fine, setup works good (tested on other computer) and furthermore the installed application almost works correctly. The only exception is a button calling function which is creating a new txt (something like a draft of a "save" file) file in a folder where the application is installed. Clicking this button cause instant crash of the whole application. Nothing else happens, no error message, the app just turns off.
I assume that the problem lies in access rights to the folder/administrator rights.
I've added txt file with the same name in the application folder using "File System" window in setup project, deployed and installed again. Even when the file exists the problem happend again (probably because of access rights when trying to override file content).
It's may be important that everything worked while running app through VS, also using .exe works fine on any computer. The problem is only with application installed using setup.
I'm not sure where the problem is so it's hard to show some code, to be honest i'm not even sure if it's a problem with code, maybe it can be solved with setting some setup project properties?
I would like to store some data locally between two sessions, i've choosed txt file because it's light and simple even if it's not the most elegant way.
I expect that installed application will be able to create and override txt file in it's folder.
P.S. if you need any code, screenshots or information about my setup please let me know in comments section, I will provide what's necessary
At the moment you install your program you're having administrator-rights. So the folder where your application is, also was created with administrator-rigths.
If you want to store data to this folder, you'll have to run your application as administrator. (not the best idea)
Otherwise you can change your code to write your file at runtime to a different location where you don't need administrator-rights.
For example:
string path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
will give you: "C:\Users\MyUserName\AppData\Local"
string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
will give you: "C:\Users\MyUserName\AppData\Roaming"
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
will give you: "C:\Users\MyUserName\Documents"
And some error-handling around the saving of the file would be very nice and helpful ;)
Thank you everyone for solution and knowledge, the problem was as I assumed (access to the path denied).
I was using this code to create a path:
Directory.GetCurrentDirectory() + "\\SyntyhCitySave.txt";
Creating a file in a special directory instead of application folder works, that's the solution for my problem:
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\SyntyhCitySave.txt";
Tomtom answer marked as accepted.
I want to make a working program written in Java on Mac available to a Windows user, but the connection fails on Windows with a strange error message indicating Windows is looking for the DB in C::\windows\system32. The SQLite DB is located in the same folder as the Java program:
Connection conn = DriverManager.getConnection("jdbc:sqlite:Databasess/Logic1.sqlite");
I've made a JAR and put it in a folder called Aurora, so it looks like this:
TeachingMachine
Aurora.v2.jar
Images
Audio
databases
Logic1.sqlite
Logic2.sqlite
Transfer the entire folder to another Mac and it works perfectly.
Transfer the same folder to my HP running Windows10 and it immediately gives me an error that I had copied from my HP to my Mac:
JAVA.SQL ‘SQLEXCEPTION: path to ’databases/Logic1.sqlite’: C:\windows\system32:’databases’ does not exist
I've searched for pleas for help regarding windows\system32, and larger portions of the error message. I've found some people whose questions involved gremlins in their code for making a connection to SQLite or other databases, but nothing so far mentioning the problem I've outlined here.
There is a folder for system32 on my Windows PC, but I'm trying for a single program that I can maintain and distribute to people running various operating systems. It would be self-defeating to have to copy my databases into system32.
This is the same basic code for connecting I've been using for over a year. There is, of course, no mention of system32.
Connection conn = null;
try {
Class.forName("org.sqlite.JDBC");
conn = DriverManager.getConnection("jdbc:sqlite:databases/Logic2.sqlite");
return conn;
}catch (Exception e)
The expected results are what I get on any Mac that I've tried it on, and the actual result when I run the same code on Windows 10 is that I only get one error message.
The problem you're running in to is the default directory that the process is using.
On windows, it's apparently using c:\windows\system32.
On the Mac, it's using your applications folder.
So, you need to either specify an absolute path for your database URL, or you need to change your current working directory for your application.
I have a WPF application that displays loose XAML FlowDocuments (with Frame) that are located on a CD or DVD. This has worked just fine in the past, but now all of the sudden the program is crashing on a specific computer. The very strange thing is that this computer is 100% identical to other computers that this works just fine on (their hard drives are even imaged from the same hard drive image).
Not only does my application crash, but when I simply try to view these loose xaml files with internet explorer, it also cannot display them (they display fine in IE on other computers). Clicking on the more information button in IE shows me:
System.IO.IOException: The media is write protected.
Which I'm assuming is the same exception that my application is getting, though I can't actually tell the actual exception my program is getting because putting a try-catch around the Frame.Navigate function that I'm calling to display the xaml files doesn't actually catch this exception (Bonus Question: Why is that?), the program just crashes (and I don't have VS on this computer or remoting capabilities so I can't run the debugger).
Even more strange is the exception, why would it matter if the media is write protected if all I'm trying to do is read it?
I have a WPF application that is designed for a touchscreen kiosk. Users will not have access to a keyboard or mouse. The application runs fine when started normally from the program icon in windows. However, when it is set up to run automatically at startup (by replacing the Windows shell using a registry key), the application does not function properly.
The application reads an XML file that lists available videos, then displays buttons to show the videos. When run in "kiosk mode," it does not seem to have access to the files in its media directory (the XML file and presumably the videos as well). I suspect that because the application is running in place of the windows explorer, it is missing resources it needs for file access that are normally loaded by windows explorer.
I have not been able to find any info on this - there is plenty of info on how to get an app to run at startup, but not much on how to make sure it will actually function in that environment. The PC is running Windows 7 Professional.
Is my assumption about the problem correct, or is it likely something else (e.g. permissions - we checked the permissions, but maybe they operate differently when you replace the windows shell?) If it is because needed resources are not loaded, does anyone have pointers on how to make sure my app loads them?
Perhaps you have file access occurring via a file dialog? This might explain a bit further. What is the minimum functionality needed to create Shell Replacement for Windows?
because you have stopped windows default running explorer.exe , your program can not get access to default xml directory therefore you should specify the complete path for example like below:
stream = File.Open(#"C:\x86\Debug\xml.xml", FileMode.OpenOrCreate);
We have a WPF application that was developed on Windows 7 using VS 2010 and .NET 4.0 framework.
I have created an install package for it using the Visual Studio Installer.
When running on XP it appears to go into a bad state after using the win32 OpenFileDialog. It took me a while to track this down, as it doesn't fail right away. The dialog appears, you select the file you want to open, it opens up and is displayed on the screen. I was using it for about two minutes and then it crashed. I get the message that my program has encountered a problem and needs to close.
I can now run my application, open a file and make it crash right away, since a specific action always makes it crash. It does on any file I open, even a new one.
So I tried opening the same file without using the OpenFileDialog, I have a MRU list that I selected the file from, and it works flawlessly. I have not been able to make it crash.
Anyone experience similar behavior or have any ideas?
Since I do not have a debug environment on the XP machine I tried putting in some tracing statements within the application to write out to our log file where it is and what value some variables have. The really strange thing is that as soon as the OpenFileDialog.ShowDialog method is called all writing to our log file stops. I am just using standard file I/O and actually open, write and then close the file for every log message. This makes it difficult to debug this way, but also further supports the fact that something is gone wrong in the environment.
I have tried on four different XP machines, all with the same results.