C# Button to view folder just created - c#

So in my application I have created, there is a button that will create a folder in a user-selected location, I want to add another button to my application that when clicked, will pull up this folder that has just been created.
I have looked into using Process.Start($#"C:\Users}); but have no way of using the folder path as it has not been created before starting the application. How would I get around this?

You can do it like this.
Process.Start("explorer.exe", #"Path of the folder that you want to open");
Just make sure the user by which you are running the application must have access to the folder. Otherwise, you might get issues related to access control.

Related

Is it possible for a user to only select file save location once?

I've been trying to learn how to handle saving normal .txt files in UWP, and have realized that it's quite locked down compared to WPF, especially in the sense of what folders you can access without requesting the user to select a location. I have searched for various ways this might be possible but found no working answer.
Question Description:
I basically would love to know if this is possible, and preferably a point in the direction where I can learn how exactly to do this.
Application settings page requires user to select folder where files are saved.
Application remembers this between launches (unsure if this is possible, but I can't require the user to select the folder on every launch)
Application saves files to the specified folder.
In my understanding, this should be possible, as the user is the one specifying the location via filepicker, but is it possible to have this work between launches so that the user wont be required to re-select the save folder?
I need to figure this out, as I would like my application to support selecting attached network drives, cloud storage folders, etc.
Any help is very much appreciated, and if there are any questions I will answer them to the best of my ability.
Fow this purpose there are two access lists designed: FutureAccessList and MostRecentlyUsedList. Once the user has picked up the folder with the picker, you add it to such list and receive a token, which you save for future purpose in LocalSettings:
ApplicationData.Current.LocalSettings.Values["MyFolder"] = StorageApplicationPermissions.FutureAccessList.Add(pickedFolder);
Then later, once you want to access that folder, you can do it like this:
StorageFolder folder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync(ApplicationData.Current.LocalSettings.Values["MyFolder"].ToString());
You can't save a StorageFolder or a path to it in settings, hence the UWP app needs permissions to access the folder. Using above access lists solves this problem.
I believe you want to save user settings and keep it somewhere so that next time when they launch the application, they can use the same settings.
Please check out this tutorial from Microsoft, which describes how to do exactly that.
https://msdn.microsoft.com/en-us/library/bb397750(v=vs.110).aspx

Explorer Namespace Extension- what is the entering method of Save in third party application?

I have a program with Namespace Extension that is based on linking (the folders does not exist locally).
Whenever i try to save a file under the folder that is using the ShellExtension i get an error:
C:\folderPath...
Path does not exist.
Check the path and try again.
I try to find the entry point that explorer is calling in order to create the folder just before it tries to save, yet all my attempts seem to fail.
I can catch the open event by breakpoint on "OnCommonDialogOKButtonClicked" method.
maybe this is an explorer bug, yet i'm not certain.
I have found on some external link that is associated with ShellExtension the following information:
linkshellextension and i quote:
Unfortunatley this is a bug in Explorer, and I don't have a clue how to come around this in explorer.
If you start the symlink to an .exe from a command prompt it works fine, and even third party explorers like SpeedCommander can do this, but explorer seems to have a limitation
Does anybody know the registry hack to enable this in explorer.exe? Drop me a line.
where is the entry point?
Is it a poor design of explorer?
I have to create the folder while navigating in order to solve the problem?
The folder must be created and exist locally whenever the save button is clicked.
I'm guessing you're using EZNamespace (according to the method you supplied) - which internally, it's called after the file dialog is destroyed.
which is poor design by them.
they suggest to create all of your folders while navigating - but i found another way.
The reason it happens, is because when the dialog suppose to close, the path should exist (file dialogs usually are created with an option that says "PATHMUSTEXIST" or "FILEMUSTEXIST" in case of open file dialogs - this cannot be changed after the 3rd party application created the dialog.
i'd suggest to try and implement IObjectWithSite in your custom virtual folder, here's an example:
http://blogs.msdn.com/b/winsdk/archive/2015/03/24/how-to-register-for-file-dialog-notifications-from-shell-namespace-extension.aspx
Just change all "open" to "save" and it will work.
eventually what this does, is that it hooks and registers the IFileDialogEvents for that specific dialog. then you can control some actions around it (for example, use "OnFileOk" instead of your above method, which allows you to cancel the "Ok" with your validations, and also get the actual IShellItem selected.
Whenever "OnFolderChange" is called, you can create your folder, and delete the old one:
https://msdn.microsoft.com/en-us/library/windows/desktop/bb775880(v=vs.85).aspx
Just make sure to not destroy it when the "ok" is eventually clicked, you may delete the folder when the dialog is destroyed (so if user will decide to cancel, you will not have junk folders in your file system).
this should be done here:
if (m_fileOpenDialog != NULL)
{
m_fileOpenDialog->Unadvise(m_cookie);
m_fileOpenDialog->Release();
m_fileOpenDialog = NULL;
m_cookie = 0;
}
just make sure to keep a flag if you pressed the "ok" and not delete the folder.
If the folder exists, the file will be created in the designated file system (you MUST make sure that your virtual file's GetDisplayName will point to the real file system path.
another important note, whenever "OnFileOk" is called, your file will not be there yet (as this runs on the main thread of the 3rd party application). you will have to wait for it to finish writing itself to the file system, then handle it if you want.
As this post is old, if any more concrete examples are needed, just hit with a comment and i'll supply.
Good luck.

Override SaveAs Method of foreign Program/Process

Idea of the Program:
I´m developing a WinForm-Application in C-Sharp .NET-4 which will allow me to import a Folder with Files and Subfolders into a MySQL-Database and also show me these Files and Folders in an Explorer-like set of Treeview and Listview. By a Double-Click on a Filename in the Listview, the file will opened with the default Program.
The Main-Goal of this Software is to be a Multiuser-Project-Manager.
The Problem:
Once the file is opened, its outside of my Program. I can´t control the foreign Program.
The Question:
Is there a way to override/control for instance the SaveAs-Method of such foreign Proram to save the File under my conditions e.g. to save them back to my database and not to the filesystem.
I´m grateful for any answer.

Get the folder path under cursor?

I'am working on my small project: Crypt container. To unlock it - just plug-in specifig usb flash-drive and unplug it to lock container.
So, GUI of program is very simple - just ListView. If you want to add files into continer - drag'n'drop items to them.
But i have a problem - when user want to decrypt his file, he drag them in container and drop to desktop (or specific folder). And my task is to know, where user wants to put a file. If he drag file to folder - i should unpack it to folder, if he drag it to flash-drive - i should unpuck it to flash-drive.
Yes, i found one solution of my problem: http://www.codeproject.com/KB/files/DragNDrop.aspx , but i realy not understand that mechanism with tempDirectoryWatcher and Hashtables.
Maybe somebody know easy way to get path to object (folder, drive, etc.) under cursor?
Your data object should expose FILEGROUPDESCRIPTOR and FILECONTENTS. The user might drop onto something other than a folder, like an email message, or into a virtual folder like an FTP site or a ZIP folder

Standard way of prompting user to select folder to write a file to?

My goal is to have a button that, when clicked, pops open a 'Select Folder' window. I'd like to work with the path they selected afterwards.
I did a bit of reading around on this and I kept coming up with the FolderBrowserDialog class from Windows.Forms. Is this still the accepted means of capturing the path for ASP.NET AJAX? If so... will this work on non-windows computers?
Thanks
No you can't mix use FolderBrowserDialog on ASP.NET.
If you want them to browse their computer for a folder name, I'm sorry but that's not possible for security reasons.
If you want them to browse a folder on your server, you will have to design a system that will allow them to do that.

Categories

Resources