Get Drive icon by mime type - c#

I'm building a windows C# Drive App, and wish to display the thumbnails for a handful of folders.
For files that exist in a drive, I know you can get the icon by using the IconLink parameter.
How can I do this file that doesn't exist (yet), using the MimeType of the file?

If you have the file extension you can get this from the registry, for example:
HKEY_CLASSES_ROOT
.avi
On my machine, the (Default) value on that key is VLC.avi.
Now find the key with that name:
HKEY_CLASSES_ROOT
VLC.avi
And there you should find a subkey called DefaultIcon, which in my case has a (Default) value of "C:\Program Files (x86)\VideoLAN\VLC\vlc.exe",0
From here you should be able to get the icon from .exe path.
Sometimes DefaultIcon contains the path to a .dll followed by an index. For these you could check this SO question for details on how to extract the image itself.

You may want to try Uploading thumbnails. As discussed,
For shortcuts and other file types that Drive can't render, you can provide a thumbnail image generated by your application. Upload a thumbnail by setting the contentHints.thumbnail property on the File resource during an insert or update call as follows:
Set contentHints.thumbnail.image to the URL-safe Base64-encoded image
Set contentHints.thumbnail.mimeType to the appropriate type for the image format
If Drive can't generate a thumbnail, it will always use yours if you provided one.
In addition to that, note that thumbnails are invalidated each time the content of the file changes. When supplying thumbnails, it is important to upload new thumbnails each time the content is modified.
Also, check suggested solutions in the following SO posts and see if it will help you:
Permanent links to thumbnails in Google Drive API
Unable to get thumbnail using Google Drive API

Related

Have a user upload an image to the Android Resources/drawable folder

I need the user to be able to upload an image, and then have the image be able to be accessed later for drawing it. I only know how to show an image in the Android Resources/drawable folder. I don't think it is possible for a user to upload an image there, so is there another place they can upload it, and then have the image to be used? I don't know how to have the user to be able to upload it either.
I only know how to show an image with the xaml code <Image Source="image.png"/>, where image.png is in the Android Resources/drawable folder
Since Resources contained in out raw directory of our project will be packaged inside our APK and will not be writeable at runtime.
So I highly recommend that you use Internal or External Data Storage to store your images and text file.
For more details, you can check: https://learn.microsoft.com/en-us/xamarin/android/platform/files/
And at the bottom of this page:External storage, there is a example which function is to save text file in External storage, it should be helpful for you.
The sample link is here: https://github.com/xamarin/monodroid-samples/tree/master/LocalFiles
If you want to choose Photos and Video, you can use MediaPlugin of jamesmontemagno. Of course , you can achieve this function yourself.

How To Get the images filename which that stored in resource file .resx

I needed a way to store images, so i found the best way is to create a resource file and store them in it, however i choose the option {Link at Compile Time} so it creates a resource folder in the project,
but when i call for an image it returns Bitmap Image file instead of the image URL or filename or image path, I need it this way because i'm developing a web API so i don't wanna send an image but i want instead to send its URL/path so is there a way to get image URL/path from resource file since it's already there
here is an image explain where it is in resource file:
The compiled code has the resource (the image in your case) itself embedded. The file path of the resource is evaluated at compile time but is not included in the compiled code.
Unless you are using a convention like resource name = image file name, you cannot get its path.
It is the very purpose of resources to make you independent of files.
You should probably include the image name or image url as string resource instead of the image itself.
Use "Add New String" instead of "Add Existing File...".
See also SO question: ASP.NET Get physical filepath from URL
If you really want to store images inside your assembly file and return that images URL's in web responses, you can apply some name encoding scheme and return some resource name based strings, for instance http: //www.mysite/stored-images/{resource-name}, where resource-name could be _6aa_Left.
Additionally you should implement route handler, that for path /stored-image/* will write into response stream your actual image bytes from appropriate resource when image will be required.

File saving issue Windows phone 8.1

I am facing the following issue while performing the save operation on a windows 8.1 phone
a. Let us assume there is a a file named test1.doc is downloaded to a default location in the sdcard. SDCARD - Testfolder
b. We try to edit/open the file using the office 365 present in the phone and try to save it. It does not save it in the same location i.e. TestFolder.
c. It prompts the user to save in the file in the default folder present in phone for eg in the above case since it is a .doc it saves in Documents folder.
Based on the file extension, it will try to save them in the respective default location i.e. mp3 will be saved under music, .jpg or png will be in picture, .mp4 under videos and .doc,.xls,.txt, ppt under documents.
Pl. refer to the below link
https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn639127.aspx
d. And during save it also modifies the file name by appending (1) to the file. User is also given the option to modify the file name before saving.
Where on the tab and desktop it is allowing us to do the save on the same location.
I would like to know if it is a know limitation on the windows phone or any thing needs to be done to make the file save in the same location. Any input on this will be of great help.
That is the platform norm (I am not calling it as "limitation"). Every app has access to its own IsolatedStorage and media libraries depending on the access requested in manifest.

C# check if date of upload of the image is newer than some date

The user uploads an image which I name as logo.png and I save it in a folder. The user can upload new image anytime he wants. I have 7 files in the same folder.
I get that image via API. At the moment, I download the image every time I run my program. What I need is a flag to know if the user uploaded a new image than the one I already downloaded. If not - don't download the file. if yes - download it. How can I find out if the user uploaded a new file?
I know that I can use a db field for this, but is there a property of the Image class, or the FileSystemInfo class which can tell me this?
FileSystemInfo has LastWriteTime property which Gets or sets the time when the current file or directory was last written to.
refer this link : http://msdn.microsoft.com/en-us/library/system.io.filesysteminfo.lastwritetime(v=vs.110).aspx

Windows API: Assign Icon of filetype X to my file

I've read about icon handlers, but I am unsure how to work with them.
Let's say I have a C# application (or simply a Windows filesystem object such as a .LNK file) and I want to assign it the icon, a PDF File currently is using (or a MS Word file), though the application is not a PDF file itself.
How are icons assigned / where is that association saved? When using tools such as Resource Hacker I can find the icons within application files (of course a PDF file does not have an icon itself). In the registry under HKCR I can find all file types and their respective openers, where are the icons defined? This classifies as multiple questions - I am most interested in how to assign the system's currently assigned filetype icon (e.g. PDF) to my application.
In HKEY_CLASSES_ROOT there will be an entry for the file extension, for example .pdf. The string under this key is the name of a file type, in this case AcroExch.Document. Look up that key, again in HKEY_CLASSES_ROOT, and you will find either a DefaultIcon or CLSID entry. If it's a CLSID you will need to do one more level of indirection - on my system I end up at HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{B801CA65-A1FC-11D0-85AD-444553540000}. Under the DefaultIcon key you will find the full path to the file containing the icon, and the icon number within the file.
You will need to extract the icon from the file and put it into your application. Note that the icon will be trademarked and/or copyrighted by the company that created it - nobody will come after you if it's for your own personal use, but if you release an application using someone else's icon you could find yourself in trouble.
For .LNK files it should be easy. Just right click, "Properties", "Change icon" and in the next dialog "explore". Search the EXE file of e.g. adobe acrobat, the file icon normally sits in the exe file as secondary icon.
For me the path qould be "C:\Program Files (x86)\Adobe\Reader 10.0\Reader\AcroRd32.exe"
Okay, bad example, the document icon is actually in AcroRd32.dll in the same path, but normally you don't have to search much.

Categories