I have a custom library in my C# program which will open a custom file dialog to a custom location, and all I need to do is call it to a button, but every time I try this, it says that there is an issue with the Application.Run(new Form1());
saying an attempt was made with an incorrect format. Is this a case of me placing the code in the button rather than the openFileDialog
code area? Whenever I try to call a normal fileDialog
, it runs the default Windows version. Here is my code:
public partial class Form1 : Form
{
ALCGalleryLib.ALCGallery theGallery;
ALCGalleryLib.ALCGalleryFile aFile;
string tempFile;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void showOpenDialog_FileOk(object sender, CancelEventArgs e)
{
theGallery = new ALCGalleryLib.ALCGallery(); // this will create a new gallery object and connect to the details it already knows about (it gets them from the registry)
aFile = theGallery.showOpenDialog("All Files,*.*|Excel Workbooks,*.xls?"); // this call will show the gallery dialog and allow you to pick a file. it will get returned in the aFile object (or null if nothing selected)
if (aFile != null)
{
tempFile = aFile.saveToDisk(); // save the aFile object to disk as you will not really be able to do anything with it, and anyway, you probably do not need to do anything else with this object. this will return a temporary filename
// or you can choose where is gets saved with:
// tempFile=aFile.saveToDisk("some filename.xlsx");
// or assign your filename to tempFile and then...
// aFile.saveToDisk(tempFile);
// either of the above calls will save the file from the gallery to disk and return the filename in tempFile
}
else
{
// nothing was selected
}
}
private void openFile_Click(object sender, EventArgs e)
{
theGallery.showOpenDialog("All Files,*.*|Excel Workbooks,*.xls?");
}
}
If you have a Windows 64-bit
operating system, it is a conflict between your application and ALCGalleryLib, one is 32-bit and the other one is 64-bit.
If ALCGalleryLib is on 32-bit, see Project Properies, Build Tab, Platform Target must be x86 and not Any CPU or x64.
If ALCGalleryLib is on 64-bit, see Project Properies, Build Tab, Platform Target must be x64 or Any CPU.