473,395 Members | 1,823 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,395 software developers and data experts.

Upload File. File Type Question.

Hello,

I created a script to upload a file.
To determine the file type I am using userPostedFile.ContentType.

For example, for a png image I get "image/png".

My questions are:
1. Where can I find a list of all the types which can be returned?
For example, if it is a Word document will it return "document/doc".
I would like to see a list of it. I can't find it anywhere.

2. How can I get File Type and File Extension in two different
variables?
For "image/png" I would like to get:
FileType = "image"
FileExtension = "png"

Thank You,
Miguel

Nov 19 '05 #1
3 3140
Shapper,

While I'm not positive of where to find a list of all file types (I'd google
for them myself) splitting the type and extension is pretty easy just use
the string object's split function.

Dim FileArray() As String = FileType.Split("\")

Now the string array FileArray will contain two values: FileArray(0) =
"image" and FileArray(1) = "png"

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:uC**************@TK2MSFTNGP15.phx.gbl...
Hello,

I created a script to upload a file.
To determine the file type I am using userPostedFile.ContentType.

For example, for a png image I get "image/png".

My questions are:
1. Where can I find a list of all the types which can be returned?
For example, if it is a Word document will it return "document/doc".
I would like to see a list of it. I can't find it anywhere.

2. How can I get File Type and File Extension in two different variables?
For "image/png" I would like to get:
FileType = "image"
FileExtension = "png"

Thank You,
Miguel

Nov 19 '05 #2
Hi Justin,

Thanks.

I Googled it and I couldn't find any information about it.
I thought I would get that information on MSDN under
userPostedFile.ContentType but I had no success.

Does anyone else knows where I can I find this information?

Thanks,
Miguel

"S. Justin Gengo" <sjgengo@[no_spam_please]aboutfortunate.com> wrote in
message news:Ok**************@TK2MSFTNGP15.phx.gbl:
Shapper,

While I'm not positive of where to find a list of all file types (I'd google
for them myself) splitting the type and extension is pretty easy just use
the string object's split function.

Dim FileArray() As String = FileType.Split("\")

Now the string array FileArray will contain two values: FileArray(0) =
"image" and FileArray(1) = "png"

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:uC**************@TK2MSFTNGP15.phx.gbl...
Hello,

I created a script to upload a file.
To determine the file type I am using userPostedFile.ContentType.

For example, for a png image I get "image/png".

My questions are:
1. Where can I find a list of all the types which can be returned?
For example, if it is a Word document will it return "document/doc".
I would like to see a list of it. I can't find it anywhere.

2. How can I get File Type and File Extension in two different variables?
For "image/png" I would like to get:
FileType = "image"
FileExtension = "png"

Thank You,
Miguel


Nov 19 '05 #3
You're really approaching this from the wrong angle. The browser doesn't
know what the file type is. It only knows what the file extension is. It
then makes its best guess as to the MIME type of the file. There are not
MIME types for every file extension. Therefore, you're not necessarily going
to get information about the type of file via the MIME type. Instead, I
recommend that you do the following:

1. Identify exactly the requirement regarding what type of file is being
uploaded. You're not able to determine the "type" of just any file uploaded.
Ever looked through your local file system in Windows Explorer? It has a
column called "Type" which shows a friendly name for the "file type" of the
files in the system. In most cases, it displays a friendly name for the file
type. However, in some cases, you'll simply see the file extension, as in
"EXT File." This happens when Windows does not have a registration for that
file's extension. Therefore, you need to determine the reason that your app
seems to need to identify the "file type" of the file being uploaded. It is
not too difficult to identify a text file versus a binary file, for example.
But you haven't mentioned the reason you need to identify the "file type,"
and that will determine what your app needs to do to identify it to the
extent that you need to.

2. Use the file extension, rather than the MIME type for the file. As I
mentioned before, there are far fewer MIME types than there are file
extensions.

There are web sites that identify the types of programs that work with
various file extensions. You might want to Google them, and perhaps create a
database of file extensions mapped to "type identifiers" for the file
extensions. In general, the "file type" of a given file is identified as the
program or programs which interact with files having that extension. Many
file extensions are associated with multiple programs, and have a more
generic "file type name" applied to them, such as ".txt" files.

As an alternative, in a recent project, I built an Explorer-like interface
for working with files in a machine's local file system. I wanted it to look
like Explorer, so I wanted to include the "Type" column in the interface.
Upon researching how Explorer identifies the "file type" of a file, I found
out that it uses the System Registry, where file extensions are associated
with applications. These associations are stored in the HKEY_CLASSES_ROOT
registry. The file extensions are stored in keys with the name of the file
extension. The default value for that key contains a string that identifies
the default application used to open that file type. Under the keys for the
file extensions are the keys for each of the file extension keys' default
application identifier. So, you need to read 2 registry keys for each file
extension. Here is a bit of code that you can use:

using Microsoft.Win32;

public static string GetFileType(string ext)
{
RegistryKey rKey = null;
RegistryKey sKey = null;
string FileType = "";
try
{
rKey = Registry.ClassesRoot;
sKey = rKey.OpenSubKey(ext);
if (sKey != null && (string)sKey.GetValue("", ext) != ext)
{
sKey = rKey.OpenSubKey((string)sKey.GetValue("", ext));
FileType = (string)sKey.GetValue("");
}
else
FileType = ext.Substring(ext.LastIndexOf('.') + 1).ToUpper() + " File";
return FileType;
}
finally
{
if (sKey != null) sKey.Close();
if (rKey != null) rKey.Close();
}
}

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.

"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:uC**************@TK2MSFTNGP15.phx.gbl...
Hello,

I created a script to upload a file.
To determine the file type I am using userPostedFile.ContentType.

For example, for a png image I get "image/png".

My questions are:
1. Where can I find a list of all the types which can be returned?
For example, if it is a Word document will it return "document/doc".
I would like to see a list of it. I can't find it anywhere.

2. How can I get File Type and File Extension in two different variables?
For "image/png" I would like to get:
FileType = "image"
FileExtension = "png"

Thank You,
Miguel

Nov 19 '05 #4

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

Similar topics

3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
4
by: DH | last post by:
I have a "file upload form" that works OK, but I have been unsuccessful in my attempt to also resize the uploaded .JPG (if it is too wide), over-writing the original .JPG, and then create and save...
6
by: Mosher | last post by:
Hi all, this might be more of an html question but I think it can be done in PHP, so I will ask here. I have an html form that allows for .pdf file uploads. This script will serve two functions...
4
by: Matt Jensen | last post by:
Howdy I've got a rather strange issue occuring. I used forms based .NET authentication, although I'm also setting some session variables when people login. However, I've found when people use...
0
by: SEMIH DEMIR | last post by:
Sitelerden birinde verilen yabancı kaynakli bir scriptti duzenledim yanlız birseyin içinden bir turlu cıkamadım işin aslı ilk defa persistin upload componentini kullanacam yanlız suanki haliyle...
1
by: Marko Vuksanovic | last post by:
I used the following code for implementing a file upload progress indicator, using UpdateProgress Panel, though I have a problem that FileUpload.Has File always returns false. Any suggestions what...
7
by: pbd22 | last post by:
hi. i am having probs understanding how to grab a file being uploaded from a remote client. i am using hidden input fields for upload such as: <input id="my_file_element" type="file"...
6
by: =?ISO-8859-1?Q?J=F8rn?= Dahl-Stamnes | last post by:
I have a strange problem when uploading a PDF document to a web-server. When I try this to a web-server running Apache 2 on a FC 4, it fails. Firefox says that the document contain no data. If I...
4
by: =?Utf-8?B?Y3NsZWltYmFjaA==?= | last post by:
I am having trouble with uploading a file to a website. I can not figure what I am doing wrong. I have a .asp file that you put a username and password in that is connected to a database. One of...
43
by: bonneylake | last post by:
Hey Everyone, Well this is my first time asking a question on here so please forgive me if i post my question in the wrong section. What i am trying to do is upload multiple files like gmail...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.