SaveFileDialog in WPF on Windows XP shows empty file list - wpf

I'm using a Microsoft.Win32.SaveFileDialog in a WPF application which is fine in Windows 10 but some users are still using Windows XP and initially the dialog shows no files.
Changing the file type to another type updates the list. It appears to only be the initial loading.
I've used System.Windows.Forms.SaveFileDialog, using a "Using", making sure the Dialog has an owner Window and using BeginInvoke on the current dispatcher.
lSaveFileDialog = new Microsoft.Win32.SaveFileDialog();
lSaveFileDialog.Title = "Datei speichern";
lSaveFileDialog.InitialDirectory = pFilenameElements.IFilenameElement_DirectoryInfo.FullName;
lSaveFileDialog.Filter = "Word Dateien (*.doc)|*.doc|Alle Dateien (*.*)|*.*";
lSaveFileDialog.RestoreDirectory = true;
lSaveFileDialog.FileName = pSuggestedFilename;
if (lSaveFileDialog.ShowDialog() == true)
{
return lSaveFileDialog.FileName;
}
I expect the Dialog to open and display other Word files in the current folder but it only does that if I switch the filter to "All" and then I see everything. Switching back to "Word" and I see the Word files.
On Windows 10 there is no problem.

Related

Allow only one Chromium app instance

I have the Chromium source on Windows 7, and launch my custom app with the --app="..url" switch through a .bat file. How can I prevent users from opening more than one instance of my Chromium app? This includes opening the .exe directly, using the .bat file and by selecting "Chromium" from the jump list menu on the task bar.
If the app is launched with the --app="...url" flag, then the following solution will prevent further "instances" of Chrome being opened. I say "instances" because Chrome doesn't actually create new Chrome base processes. Instead, it opens a new window with a process used for rendering that particular window.
So, when the app is in --app mode, all you need to do is prevent new windows from opening. This can be accomplished by modifying the OpenApplicationWindow() method within the Chromium source code Application_launch class: chrome/browser/ui/extensions/application_launch.cc.
...
OpenApplicationWindow(const AppLaunchParams& params) {
browser = chrome::FindBrowserWithProfile(profile, params.desktop_type);
#endif
WebContents* web_contents;
if (!browser) {
browser = new Browser(browser_params);
web_contents = chrome::AddSelectedTabWithURL(
browser, url, content::PAGE_TRANSITION_AUTO_TOPLEVEL);
web_contents->GetMutableRendererPrefs()->can_accept_load_drops = false;
web_contents->GetRenderViewHost()->SyncRendererPrefs();
}
else {
web_contents = browser->tab_strip_model()->GetActiveWebContents();
}
browser->window()->Show();
...
*NOTE: There should be some Windows 8 code in this method already. The idea is to remove the conditions for Windows 8 Metro Mode, so new Windows are always prevented.

Application showing an exception"file not found "

I created an application in VS2010 with operating system WINDOWS XP.
Now, I updated the os to WIN 7 and also updated the location of the application.
So, while running the application for opening a file using open dialog box it showing some exception like"File Not Found".
It was working fine with WIN XP, but now it showing this error, if we keep that perticular file in bin folder its working fine , but if we choose a file from other drive or a folder it showing error.
enter code here
string chosen_file = "";
ofd.Title = "Open a file";
ofd.FileName = "";
ofd.Filter = "Text Files(*.txt)|*.txt|Rich Text Box(*.rtb)|*.rtb|Word Document(*.doc)|*.doc|HTML Pages(*.htm)|*.html|Cascading Style Sheet(*.css)|*.css|JAVA(*.java)|*.java|video file(*.wmv)|*.wmv|All Files(*.*)|*.*";
if (ofd.ShowDialog() == DialogResult.OK)
{
chosen_file = ofd.FileName;
// richTextBox2.LoadFile(chosen_file, RichTextBoxStreamType.PlainText);
var fileInfo = new FileInfo(ofd.FileName);
fileInfo.Length.ToString();
byte[] buffer = new byte[fileInfo.Length];
int length = (int)fileInfo.Length;
FileStream fileStream = new FileStream(fileInfo.Name, FileMode.Open, FileAccess.Read);
fileStream.Read(buffer, 0, length);}
My guess is you referenced a hard-coded path, probably to your "Documents" folder, rather than using an environment variable. With the change from XP to 7, that directory changed. I can't recall what the directory was for Windows XP, but it's now /users/username for Windows 7. Either way, you would be better off using an environment variable.
Look through your program for Documents and Settings and see if you can find it. If you go to a command prompt and type set, it should give you a list of environment variables you could use in place of whatever you were using.

How to disable file in use check in WPF OpenFileDialog?

My WPF app is using the Microsoft.Win32.OpenFileDialog to select a SQL Server 2008 database to open.
It works OK but for one issue: When the database selected in the dialog was previously opened at some time since last boot, the file seems to be held open by SQL server in the background (even when it is not opened by my app and my app has been restarted). This causes a "file is used by another application" warning when OK is clicked in the OpenFileDialog and i can not use the dialog to open that particular database until the computer is rebooted. It seems the OpenFileDialog tries to open the file selected and doing that discovers that it is already opened by another app (SQL Server). How do i disable the OpenFileDialog from trying to open the selected file and just return the filename of the selected file without any checks?
My code looks like this:
public void OpenDatabase() {
// Let user select database to open from file browser dialog
// Configure open file dialog box
var dlg = new Microsoft.Win32.OpenFileDialog();
dlg.FileName = ""; // Default file name
dlg.DefaultExt = ".mdf"; // Default file extension
dlg.Filter = "Databases (.mdf)|*.mdf|All Files|*.*"; // Filter files by extension
dlg.CheckFileExists = false;
dlg.CheckPathExists = false;
// Show open file dialog box
bool? result = dlg.ShowDialog(); // Gives file in use warning second time!
// Process open file dialog box results
if (result == true) {
// Open document
string filename = dlg.FileName;
TryOpenDatabase(filename);
}
}
The underlying option is OFN_NOVALIDATE for early Windows versions, FOS_NOVALIDATE for the Vista dialog you get on later versions of Windows and .NET. The description from MSDN:
Do not check for situations that would prevent an application from opening the selected file, such as sharing violations or access denied errors.
Which is what you see happening now, the dialog sees a sharing violation on the database file. This option is in fact exposed on the OpenFileDialog wrapper class, add this line of code to fix your problem:
dlg.ValidateNames = false;
The MSDN forum has a post about this
It is in the OpenFileDialog API, you can turn that off using
ValidateNames = false
on the Dialog.

Adobe Flex OpenWithDefaultApplication Movie

I am working on an Adobe Air application that I would like to be able to launch a movie using the default application. The code I am trying is:
var file:File = new File;
//currentMovie.ConfiguredPath = 'D:\\Movies\\TestMovie.avi';
file.nativePath = currentMovie.ConfiguredPath;
file.openWithDefaultApplication();
I have also tried this:
//currentMovie.ConfiguredPath = file://D:/Movies/TestMovie.avi'
navigateToURL(newURLRequest(currentMovie.ConfiguredPath));
The first option does nothing. No application opens, no errors, nothing. The second option worked but it launches a separate window, downloads the file to the local user's download directory then opens the file (as long as you click "Open"). This is not exactly the behavior that I was hoping for.

Open a folder and highlight a particular file with WPF

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 + "\"";

Resources