Always save specific file type in windows to one location? - windows

I'm trying to do the following I'm not sure if it's possible using VB.NET.
I want to specify default saving point for all files type for example:
In my program you choose the path "C:\Users\Markus\Pictures" for pictures and everytime you download pictures files from website, or using skype or any other program when Save File Dialog opens up (external one not via my program or connected to vb.net just the windows default one) then it will show "C:\Users\Markus\Pictures" always for .jpg .gif type of files etc...
Thanks a lot.

This bits of codes should solve your problem
SaveFileDialog1.InitialDirectory = #"C:\Users\Markus\Pictures"
InitialDirectory property represents the directory to be displayed when the open file dialog appears first time.
SaveFileDialog1.Filter = "txt files (*.jpg)|*.jpg|All files (*.*)|*.*"
Filter property represents the filter on an open file dialog that is used to filter the type of files to be loaded during the browse option in an open file dialog.
refer to this link for more info

You can programmatically modify the paths of the Windows special directories (My Pictures, etc) in the registry key:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
However, your app will have to be granted permissions to do so (see RegistryPermission Class)
Of course, this will work for those file types that have entries in this registry key, and only if an external application uses this key

Related

Opening a file **in** a batch file

I have a batch program that can be used for opening a specific file format I created. The file format is a actually a zip file with the .zip changed to .gcif.
When you run my btch file there is an input field for entering the location of the .gcif file you want to open. The .gcif is then renamed to .zip. The 7z.exe (which is in the same directory as the batch file) then unzips the file and it is processed by my batch file.
But I would like it to also work when the user finds any .gcif file, right clicks it, and selects Open With my batch file. Is there any way for batch file to detect that ithas been tasked to open that specific file?
I figured it out. When a file is opened with a batch file, the file location is passed on to the batch file as a parameter. The parameter can then be accessed using %1.
For example, if I opened the file C:/document.txt in a batch file containing this code:
#ECHO OFF
ECHO %1
The output would display C:/document.txt.
You can register a windows file handler in your system.
You might need admin rights and might need to modify the registry.
Essentially you "connect" your filextension .gcif with your batch file so windows knows that any file of this extension is connected to your batchfile
You can read something about it on the msdn site here: How to Register a File Type for a New Application
If you plan to associate one or more file types with a new
application, you must define a ProgID for each file type that you want
to associate with the application.
To create a ProgID for each unique file type that your application
handles, use these steps.
Instructions
Step 1: Note that some file types have multiple
extensions that point to the same ProgID; for example:
HKEY_CLASSES_ROOT\App.jpeg (your ProgID)
HKEY_CLASSES_ROOT\.jpg = App.jpeg (the file type mappings)
HKEY_CLASSES_ROOT\.jpeg = App.jpeg
Step 2:
Remove the ProgID values when you install and uninstall your
program.
Step 3:
Leave the file type mappings unchanged at uninstall time.
Doing so works because file type mappings are stored per user in
HKEY_CLASSES_ROOT.ext, and the system identifies the case where the
ProgID value is missing and ignores it. Leaving file type mappings
unchanged avoids the need to have conditional code that only removes
the file type mapping if the value still points to your ProgID. It is
important to avoid doing so in cases where it might have been changed
by another application and you thus cannot easily remove the value.
Step 4:
Specify a unique value for the file type description of each
file type ProgID by doing one of the following:
Leave the default value of the ProgID empty, in which case the system
uses the .ext file. Provide a localized value via FriendlyTypeName
and, for compatibility with old applications that read the registry
directly, be sure to provide the default value of the ProgID as the
file type description (that is, use the same value that is referred to
by the FriendlyTypeName in the English resource). Remarks If you plan
to associate the file with an existing application, locate an
application ProgID in the registry.
To accomplish something similar you can open your file once with Explorer and chose "Open with..." - locate your batch file and choose "always open with this application" checkbox.
The first option here is more for when you want to provide 1-click-open experience to customers for your application when they install it on their system.

How can I open a folder with an application

I have an application that can "serialize" its state as a folder with images. This folder is called, e.g., C:\Temp\MyProject.ImageExplorer and the FileSystem consists of :
C:\Temp\MyProject.ImageExplorer\Pic1.jpeg
C:\Temp\MyProject.ImageExplorer\Pic2.jpeg
...
Can I Configure Windows Explorer in a way, that a Double Click on a folder with my .ImageExplorer "extension" does not open the folder but starts my ImageExplorer.exe with the folder name as command line argument?
Can I modify the C# .Net OpenFile Selector in a way to open these "Folders" including the Filter by extension ?
You can do it but might have issues since the file type is a folder. What I would do is basically make it a uncompressed .ZIP file, You can change the extension to what ever you want so you can associate it with your application like .IZP
You can make your application setup a registry key that associates .IZP with your application and pass the path to the file in as parameter to program.exe path/to/izp/that/user/opened
You might just have to adjust the program to handle reading a container rather than a folder.

Windows Explorer and Reparse Point Files: keep Explorer from opening my files

I've implemented a user mode program and a Windows file system minifilter that creates a skeleton view of users files for a remote file storage system. It maps the remote files to the local drive. The user mode program creates a reparse tag for each file on the remote system. When a create request (e.g., CreateFile for read) is detected, the minifilter asks the user mode program to download the file. This should only happen when a program wants to open the file for viewing or editing.
But, I'm finding that Windows Explorer is triggering my files to download. I'd like to prevent the Explorer File windows and File Open/Save dialogs from
triggering downloads. And, I also want to display the file thumbnails and file
size.
[Update: I've found I can use Windows sparse files to show my remote
file size in Explorer. ]
Therefore, I have also implemented a Shell Extension, IThumbnailProvider, that downloads a rendition of the file. This provides the file thumbnails.
For my testing, I've registered the IThumbnailProvider for all files (*) and for .jpg files.
I'm seeing two interesting behaviors using a combination of Process Monitor and DebugView (both from SysInternals):
1. If I make my minifilter reject requests to open the file from Explorer, then my IThumbnailProvider is invoked.
2. If I permit open requests from Explorer, I see thumbcache.dll in the call stack trying to open the file and my IThumbnailProvider is not called. It appears that the default thumbnail provider reads the downloaded file and creates the thumbnail.
I must be missing something.
Update: if I use InitializeWithStream instead of InitializeWithFile, it appears my handler is invoked. But, that also triggers a download of the file.
There are many shell extension types which can access to your files. Icon handler can read file to create icon, Info tip handler can read file to create text hint, Data object handler can read file to create clipboard data and so on.
Questions from developer with the same problem: first and second. Solution was to create namespace shell extension. NSE can control all access to your files.

Changing default program for a file type (workaround)

I would like to specify that images of a certain type (for example, .png) open by default in a program I've written when the file is contained in a certain directory. I've seen by searching (Change Default Program for a specific folder) that this is not possible on Windows 7 or 8.
I am saving these images in this directory myself, so I have some leeway with how I name the files. For example, I could change the filename a bit... perhaps to be example.myprog.png or something similar. Is there a way to set it up so files that match this filename pattern get opened, while other .pngs (in other directories) still open in the default viewer?
I don't really want to name these PNG images example.myprog (i.e., fully change the extension), because when the user is browsing the directory in Windows Explorer, I would like the thumbnail images to still show up. Also, users will be eventually transferring these images to their own machines, where they'll want to use standard image viewers to look at them.
If this is not possible, does anyone have another suggestion for how to tackle this problem?
As you are mentioning that files should be opened in a program that you have written, try to change the code of your program to read files from the specific folder. So, by opening your program from anywhere in your pc, you should be able to open files from specified folder.

In windows, can a file name extension launch a web app?

Default programs for launching a specific type of file can be configured in windows. For example, double clicking a .doc file will open that file in Word, but you can reconfigured the default program associated with the .doc extension to launch the file in any program you want.
My question is, can you set the 'default program' to be a web app, or a URL? I have a web app that exports files that can then be re-imported into the web app. I want to be able to double click on those files and have a browser window open that automatically imports that file into the web app.
Yes you can.
There is a registry entry that maps an extension to a file type. There are registry entries for the file type indicating "verbs" that can be performed for that file type. One of those entries for the verb will indicate a command line, and the command line is completely arbitrary. As long as you can specify a URL in the command line to the browser, you can make the browser open anything you want.
Here's a Microsoft reference to get you started: Verbs and File Associations

Resources