I had a connection string to a MS Access DB file, Foo.accdb, defined and used in my project. It was defined as a connection string Setting in the Settings section of my project properties. The program referenced the connection string setting and everything worked fine.
Then I decided to replace Foo.accdb with two different DB files, A.accdb and B.accdb each of which would be used under different circumstances. I added connection strings for them in Settings and removed the Setting definition for Foo.accdb connection string.
The name of my application is Foo and the name of the Foo.accdb connection string was FooConnectionString.
But now when I build the program both in debugger and for release I get the following error message:
'FooConnectionString' is not a member of 'Foo.My.MySettings'.
The offending reference, in file FooDataSet.Designer.vb, is:
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute()> _
Private Sub InitConnection()
Me._connection = New Global.System.Data.OleDb.OleDbConnection
Me._connection.ConnectionString = Global.Foo.My.MySettings.Default.FooConnectionString
End Sub
What is going on here? FooConnectionString is not in any other file in the project directory nor in the My Project subdir. I completely got rid of it in my code and in my project properties yet it persists in FooDataSet.Designer.vb (whatever that is).
While researching this on the web I saw a recommendation to select the FooDataSet.xsd file, right click it and execute the "Run Custom Tool" option. I did this and it appears to rebuild FooDataSet.Designer.vb (the time stamp changes) but the problem persists.
I also tried removing the offending reference by manually editing FooDataSet.Designer.vb but that gave me some other error message.
Why is this old reference staying around and what can I do about it?
This is a standalone app. I'm using VS2008 Standard Ed., VB.Net 3.5
Thanks.
Open the FooDataSet XSD file in a text editor. Right click on dataset in the solution explorer and select "Open With..." and the select XML (text) Editor or open it outside the solution.
Look for the <Connections> tag near the top of the file. Remove the line that looks like this
<Connection AppSettingsObjectName="Settings" AppSettingsPropertyName="FooConnectionString" ConnectionStringObject="" IsAppSettingsProperty="true" Modifier="Assembly" Name="FooConnectionString(Settings)" ...
I am new to winforms and facing one problem in my application. I am trying to show the user to save a file using SaveFileDialog control on my form. But as soon as the user chooses his directory and saves his file, my next code which uses Directory.getCurrentDirectory() fails to point to my working directory. It seems that SaveFileDialog is causing problem here.
For eg:- I have these lines of code -
MessageBox.Show( Directory.GetCurrentDirectory( ) ); // output: C:\TestSamples\TestApp\Bin\Debug
fdSave.ShowDialog( ); // fdSave is SaveFileDialog control which will show to save file
MessageBox.Show( Directory.GetCurrentDirectory( ) ); //output: C:\Program files\outputDir (This is the path chosen by user to save file in previous saveDialog.)
Is there any solution for this so that my current working directory does not get changed or should I keep a variable to store my current working directory before saveDialog is used?
I found a possible answer in the comments on Raymond Chen's excellent blog:
in the class System.Windows.Forms.FileDialog, there is a property 'RestoreDirectory'
Well you could use the Application.StartupPath if you always wanted it to point to the bin directory
Is there a way to launch an Explorer window and highlight a file in that folder with WPF ? I've already tried the following :
Process ExplorerWindowProcess = new Process();
ExplorerWindowProcess.StartInfo.FileName = "explorer.exe";
ExplorerWindowProcess.StartInfo.Arguments = ConfigFile.File.FullName;
ExplorerWindowProcess.Start();
... but that opens the file (in my case an XML file) with the default application in Windows Explorer, which I very much don't want. I know that the Aptana tools available for Eclipse allow you the ability to select a file in the Eclipse project browser and show the file in Explorer exactly as I want, but I need a way to implement this in my WPF app.
Explorer Command Line Arguments
http://support.microsoft.com/kb/152457
Explorer [/n] [/e] [(,)/root,<object>] [/select,<object>]
/n Opens a new single-pane window for the default
selection. This is usually the root of the drive Windows
is installed on. If the window is already open, a
duplicate opens.
/e Opens Windows Explorer in its default view.
/root,<object> Opens a window view of the specified object.
/select,<object> Opens a window view with the specified folder, file or
application selected.
You will also want to put quotes around the filename like so:
startInfo.FileName = "explorer.exe";
startInfo.Arguments = "/select,\"" + ConfigFile.File.FullName + "\"";
I'm using IsloatedStorage in a Silverlight app to log information on the client, and I added a function to clear the log file. However, I have had problems with the two approaches I tried:
Approach one: use
IsolatedStorageFile.DeleteFile("log.log");
Result: This fails and returns an "[IsolatedStorage_DeleteFile]" error (No other info). The function works fine on test files, e.g. DeleteFile("test.txt"), but refuses to delete the log. I though that perhaps the log is being used, and tried to close it with
IsolatedStorageFileStream.close()
But this returns a different error "[IsolatedStorage_StoreNotOpen]". I know it is open as the previous line of code successfully logs a message.
Approach Two: Reopen the log file using the Truncate file mode,
_storageFileStream = new IsolatedStorageFileStream(logfilename, FileMode.Truncate, FileAccess.Write, FileShare.ReadWrite, _storageFile);
According to MSDN, Truncate "Specifies that the operating system should open an existing file. Once opened, the file should be truncated so that its size is zero bytes." However, it opens my log file and fills it with blank space! The filesize is left identical, the next log message is appended to the end of all of the space.
I've found a way to do this, not by closing but by disposing:
IsolatedStreamWriter.Dispose();
IsolatedStorageFile.DeleteFile("log.log");
IsolatedStorageFileStream = new IsolatedStorageFileStream(logfilename, FileMode.Create, FileAccess.Write, FileShare.ReadWrite, _storageFile);
Didn't get the 'truncate' approach to work, but no need now.
Our application has a file format similar to the OpenDocument file format (see http://en.wikipedia.org/wiki/OpenDocument) - i.e. zipped with a manifest file, a thumbnail image, etc.
I notice that OpenOffice files have a preview image of the Open Office file as their icons, both in Windows and in Linux. Is there some way to accomplish this for our files: i.e. I want a dynamic icon based on the internal thumbnail.png?
Edit 1 Wow, thanks for all the quick answers. Thumbnailer looks great for the GNOME world. Windows I'll be looking into those links, thanks. As for the comment question: programmatically OR via our installer.
Edit 2 Oh, forgot Mac. How about on the Mac? (Sorry Mac lovers!) Also are there any links or info for how OpenOffice does their IconHandler stuff - since ours would be very similar?
Windows
What you need is an Icon Handler, also known as a Thumbnail Handler. Here is an example written as an active x control.
Another resource is to look up Property Handlers, which should also point to you to the latest and greatest way of having dynamic meta data handled correctly in windows.
These are dynamic solutions - they aren't needed if you just want an icon associated with all your files - they are only used when you want windows explorer to display an icon based on what's in the file, not just the extension, and when the file changes the icon is updated to reflect the changes. It doesn't have to be an image of the file itself, either, the thumbnail handler can generate any image based on the file contents.
The property handler updates other metadata, such as song or video length, so you can use all the metadata Windows Explorer supports.
Regarding MAC support, this page says, "The Mac and Windows operating systems have different methods of enabling this type of thumbnail, and in the case of the Mac OS, this support has been inconsistent from version to version so it hasn't been pursued [for Adobe InDesign]."
OS X
Icons for Mac OSX are determined by the Launch Services Database. However, it refers to a static icon file for all files handled by a registered application (it's not based on extension - each file has meta data attached that determines the application to which it belongs, although extensions give hints when the meta data doesn't exist, such as getting the file from a different OS or file system)
It appears that the dynamic icon functionality in OSX is provided by Finder, but searches aren't bringing up any easy pointers in this direction. Since Finder keeps changing over time, I can see why this target is hard to hit...
Gnome
For Gnome you use a thumbnailer. (thanks Dorward)
This is an extraordinarily simple program you write, which has 3 command line arguments:
input file name, the file you are describing with the thumbnail (or URI if you accept those instead)
output file name, where you need to write the PNG
size, a number, in pixels, that describes the maximum square image size you should produce (128 --> 128x128 or smaller)
I wish all systems were this simple. On the other hand this doesn't support animation and a few other features that are provided by more difficult to implement plugins on other systems.
KDE
I'm a bit uncertain, but there are a few pointers that should get you started. First is that Konqueror is the file manager and displays the icons - it supports dynamic icons for some inbuilt types, but I don't know if these are hardcoded, or plugins you can write. Check out the Embedded Components Tutorial for a starting point.
There's a new (ish?) feature (or planned feature...) called Plasma which has a great deal to do with icons and icon functionality. Check out this announcment and this initial implementation.
You may need to dig into the source of Konqueror and check out how they did this for text files and others already implemented.
-Adam
Mac OSX since version 10.5 …
… has two approaches:
Your document is in the standard OSX bundle format and has a static image
This can be done by creating a subfolder QuickLook and placing the Thumbnail/Preview.png/tiff/jpg inside.
Everything else needs a QuickLook generator plugin which can be stored in either /Library/QuickLook ~/Library/QuickLook or inside the YourApp.app/Contents/Library/QuickLook Folders.
This generator is being used to create Thumbnails and QuickLook previews on the fly. XCode offers a template for this. The template generates the needed ANSI C files which have to be implemented. If you want to write Object-C code you have to rename the GenerateThumbnailForURL.c and GeneratePreviewForURL.c to GenerateThumbnailForURL.m and GeneratePreviewForURL.m (and read the Apple Devel Docs carefully ;) )
Simple zip container based demo:
You will have to add the Cocoa.framework and Foundation.framework to your project
In your GenerateThumbnailForURL.c (this is partly out of my head - so no guarantee that it works out of the box ;) ):
#include <Cocoa/Cocoa.h>
#include <Foundation/Foundation.h>
OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thumbnail, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options, CGSize maxSize)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
/* unzip the thumbnail and put it into an NSData object */
// Create temporary path and writing handle for extraction
NSString *tmpPath = [NSTemporaryDirectory() stringByAppendingFormat: [NSString stringWithFormat: #"%.0f.%#" , [NSDate timeIntervalSinceReferenceDate] * 1000.0, #"png"]];
[[NSFileManager defaultManager] createFileAtPath: tmpPath contents: [NSData alloc] attributes:nil];
NSFileHandle *writingHandle = [NSFileHandle fileHandleForWritingAtPath: tmpPath];
// Use task to unzip - create command: /usr/bin/unzip -p <pathToFile> <fileToExtract>
NSTask *unzipTask = [[NSTask alloc] init];
[unzipTask setLaunchPath: #"/usr/bin/unzip"];
// -p -> output to StandardOut, added File to extract, nil to terminate Array
[unzipTask setArguments: [NSArray arrayWithObjects: #"-p", [(NSURL *) url path], #"Thumbnails/thumbnail.png", nil]];
// redirect standardOut to writingHandle
[unzipTask setStandardOutput: writingHandle];
// Unzip - run task
[unzipTask launch];
[unzipTask waitUntilExit];
// Read Image Data and remove File
NSData *thumbnailData = [NSData dataWithContentsOfFile: tmpPath];
[[NSFileManager defaultManager] removeFileAtPath: tmpPath handler:nil];
if ( thumbnailData == nil || [thumbnailData length] == 0 ) {
// Nothing Found. Don't care.
[pool release];
return noErr;
}
// That is the Size our image should have - create a dictionary too
CGSize size = CGSizeMake(256, 256);
NSDictionary *properties = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:size.width],kQLPreviewPropertyWidthKey,
[NSNumber numberWithInt:size.height],kQLPreviewPropertyHeightKey,
nil];
// Get CGContext for Thumbnail
CGContextRef CGContext = QLThumbnailRequestCreateContext(thumbnail, size, TRUE, (CFDictionaryRef)properties);
if(CGContext) {
NSGraphicsContext* context = [NSGraphicsContext graphicsContextWithGraphicsPort:(void *)CGContext flipped:size.width > size.height];
if(context) {
//These two lines of code are just good safe programming…
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:context];
NSBitmapImageRep *thumbnailBitmap = [NSBitmapImageRep imageRepWithData:thumbnailData];
[thumbnailBitmap draw];
//This line sets the context back to what it was when we're done
[NSGraphicsContext restoreGraphicsState];
}
// When we are done with our drawing code QLThumbnailRequestFlushContext() is called to flush the context
QLThumbnailRequestFlushContext(thumbnail, CGContext);
// Release the CGContext
CFRelease(CGContext);
}
[pool release];
return noErr;
}
Info.plist
You will have to modify your info.plist file too - when you open it up it has a lot of fields pre-set. Most of them are self-explaning (or will not have to be changed) but I had to add the following structure (copy paste should do - copy the text, go into the plist editor and just paste.):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>com.pkware.zip-archive</string>
</array>
<key>UTTypeDescription</key>
<string>i-net Crystal-Clear Report File</string>
<key>UTTypeIconName</key>
<string>generic</string>
<key>UTTypeIdentifier</key>
<string>com.company.product</string>
<key>UTTypeReferenceURL</key>
<string>http://your-url.com</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>$fileEXT$</string>
</array>
</dict>
</dict>
</array>
</plist>
This will register your filetype $fileExt$ and tell the system that your filetype is a zipy format type. A nice refference, that I used here is the QuickLook IPA Plugin from googlecode
In Windows, what you need is to implement an Icon Handler. I did this many moons ago and it is not difficult as long as you know the basics of COM.
See: http://msdn.microsoft.com/en-us/library/bb776857(VS.85).aspx
For Gnome you use a thumbnailer.
for WINDOWS try this:
http://www.easydesksoftware.com/news/news12.htm
Executables have the icon inside the file (potentially multiple) as a "resource".
Data files pick up an icon based on file association.
If you want a custom icon per file that is much harder. you either need too fool the OS into thinking it is an executable and embed the icon as a resource in the file, or deep link into the OS to override the default icon selection routine.
I think, "custom own" icon can have only PE files in windows. Every other icons for file extensions are stored in windows registry.
For specification of PE file, you can look at An In-Depth Look into the Win32 Portable Executable File Format and Peering Inside the PE: A Tour of the Win32 Portable Executable File Format.
How it works in other OS, I don't know :/.
I don't know about Linux, but for Windows you can start here:
http://msdn.microsoft.com/en-us/library/bb774614.aspx
Edit: I think this interface is for the thumbnails shown in thumbnail view, not icons. Sorry for wasting your time.