473,414 Members | 1,626 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Is there an API to get File Description/Type

Example: Take .doc or test.doc and retrieve "Microsoft Word Document". This
is the 3rd column in windows explorer when you're in detail view, and it's
named "type".

I can't find it in the FileInfo class or in the shell32.dll or the
dsofile.dll. (I must be missing it, or is there no API for this?)
Nov 16 '05 #1
1 10116
Craig,

You can get this information using the SHGetFileInfo (like your earlier post
states). Here is an example of how to get the File Description/type that you
are asking about. You should be able to copy and paste this into a C# Console
app. Just be sure that the first parameter to the SHGetFileInfo method is a
valid file.

I hope that this helps you out!

---------------------
using System;
using System.Runtime.InteropServices;

namespace GetFileTypeAndDescription
{

class Class1
{
[STAThread]
static void Main(string[] args)
{
SHFILEINFO shinfo = new SHFILEINFO();
IntPtr i = Win32.SHGetFileInfo(@"d:\temp\test.xls", 0, ref
shinfo,(uint)Marshal.SizeOf(shinfo),Win32.SHGFI_TY PENAME);
string s = Convert.ToString(shinfo.szTypeName.Trim());
Console.WriteLine(s);
}
}

[StructLayout(LayoutKind.Sequential)]
public struct SHFILEINFO
{
public IntPtr hIcon;
public IntPtr iIcon;
public uint dwAttributes;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string szDisplayName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
public string szTypeName;
};

class Win32
{
public const uint SHGFI_DISPLAYNAME = 0x00000200;
public const uint SHGFI_TYPENAME = 0x400;
public const uint SHGFI_ICON = 0x100;
public const uint SHGFI_LARGEICON = 0x0; // 'Large icon
public const uint SHGFI_SMALLICON = 0x1; // 'Small icon

[DllImport("shell32.dll")]
public static extern IntPtr SHGetFileInfo(string pszPath, uint
dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags);
}
}

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Victor Engmark | last post by:
I am quite new to XForms, but I need to do a feasibility study to see whether a system I'm supposed to make can be done without any scripting or programming language (to make it simple and not need...
0
by: delphiconsultingguy | last post by:
Hi all, Spent WAAAYYY too much time trying to figure this out because there's not many good examples out there, so in the interest of sparing y'all from suff'rin same, I've pasted it into...
1
by: vj | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file? I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
3
by: Eric Lilja | last post by:
Sorry for asking so many questions, but I've just started and need to get some things working so I can do the task that is before me. Consider this (validating) schema: <?xml version="1.0"?>...
4
by: BorisBoshond | last post by:
Hi all, Hope someone is able and willing to help me with following problem. I received a xsd file from another company, our company i supposed to return xml based on that xsd. Problem is that I...
21
nathj
by: nathj | last post by:
Hi, I am currently working on a new site that offers various files for download. The file information is stored in a MySQL database and the page is produced in PHP depending on how the user got...
6
jenkinsloveschicken
by: jenkinsloveschicken | last post by:
I am developing a administrative backend for our sales dept website. They are using admin forms to manipulate what is displayed for the end user on the site. I am running into a problem with a form...
2
by: hotflash | last post by:
Hi All, I found the best pure ASP code to upload a file to either server and/or MS Access Database. It works fine for me however, there is one thing that I don't like and have tried to fix but...
4
cassbiz
by: cassbiz | last post by:
Could use some help here. This script is carrying over an image just fine but the text isn't coming over. can you see why it is not working???? from the form I want to carry over two lines of...
0
by: Hags007 | last post by:
I have a XML file I am working with. This file has been created by hand and I now need to develop a PHP script that will create it in the same format. Here is what I have thus far: $query =...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.