divteam
asked on
I want to find Content Type based on File Extention. Is there any in build function in C# or can anyone guide me how to do that?
I want to find Content Type based on File Extention. Is there any in build function in C# or can anyone guide me how to do that?
You can look in the registry in HKEY_CLASSES_ROOT for the extension and read the REG_SZ value that identifies the content type.
Here are some classes that return the file association in the OS :
http://www.codeproject.com/KB/dotnet/System_File_Association.aspx
If you are referring to content type as binary or string then you could test with readers in the IO namespace.
http://www.codeproject.com/KB/dotnet/System_File_Association.aspx
If you are referring to content type as binary or string then you could test with readers in the IO namespace.
When you say 'Content Type', is that type of file e.g. Word Document vs Web pages vs XML documents etc.?
Extension and those types are stored in Windows Registry. Try search some windows API
Extension and those types are stored in Windows Registry. Try search some windows API
http://stackoverflow.com/questions/58510/using-net-how-can-you-find-the-mime-type-of-a-file-based-on-the-file-signature
Hope it helps you.
Good Luck.
Hope it helps you.
Good Luck.
Content type - file extension mapping is available in the registry in
\\HKEY_CLASSES_ROOT\MIME\D
For example
HKEY_CLASSES_ROOT\MIME\Dat
has Extension value = .pdf.
You can write a c# method to get this type from file extension.
Hi,
Check code. I am trying to find .xml files. Modify it as your requirements.
Regards,
V.S.Saini
Check code. I am trying to find .xml files. Modify it as your requirements.
Regards,
V.S.Saini
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace ee_XmlFileArray
{
public partial class Form1 : Form
{
ArrayList arrFiles = new ArrayList();
public Form1()
{
InitializeComponent();
}
private void btnGet_Click(object sender, EventArgs e)
{
DirectoryInfo dir = new DirectoryInfo(@"D:\Zodes");
foreach (FileInfo file in dir.GetFiles())
{
if (file.Extension.Equals(".xml"))
{
arrFiles.Add(file.Name);
}
}
if (arrFiles.Count > 0)
{
for (int i = 0; i < arrFiles.Count; i++)
{
rtbFiles.Text += arrFiles[i].ToString() + "|";
}
}
}
}
}
ASKER
I am trying to upload file from outlook email into database and I need to find ContentType. I do have file extention but it does not seem to be working fine. Even though it upload successfully, when i try to view the attachment, it always error out with message saying "invalid format".
Any idea how to upload email attachments into Database?
Note:- I am using SQL 2000 and storing as image.
byte[] data = new byte[item.Attachments[a].S ize];
int bytes_read = 0;
sql = @"insert into bug_post_attachments
(bpa_post, bpa_content)
values (@bp, @bc)";
using (SqlCommand cmd = new SqlCommand(sql))
{
cmd.Parameters.AddWithValu e("@bp", bp_id);
cmd.Parameters.Add("@bc", SqlDbType.Image).Value = data;
DbUtil.execute_nonquery(cm d);
}
upload-error.bmp
Any idea how to upload email attachments into Database?
Note:- I am using SQL 2000 and storing as image.
byte[] data = new byte[item.Attachments[a].S
int bytes_read = 0;
sql = @"insert into bug_post_attachments
(bpa_post, bpa_content)
values (@bp, @bc)";
using (SqlCommand cmd = new SqlCommand(sql))
{
cmd.Parameters.AddWithValu
cmd.Parameters.Add("@bc", SqlDbType.Image).Value = data;
DbUtil.execute_nonquery(cm
}
upload-error.bmp
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.