validate file type
Can anybody share c# code to validate whether the input excel file is the real excel file or an xmlexcel file(file generated by using xmlstream)
i want this because the user uploads his excel file and am using Microsoft.ACE.OLEDB.12.0 to import it into database after import the duplicates records(available in the uploaded excel file) were dumped to an excel(thru xmlstr开发者_StackOverflow社区eam) and given to the user as a download link ..the user then uses this file to upload again...but the Microsoft.ACE.OLEDB.12.0 doesn't recognizes it..so am using Extended Properties=HTML Import but i can't find a way to retrive the data from the file(as it is an xml based excel file)
Use the magic number signature from the following URL:
http://www.garykessler.net/library/file_sigs.html
You can use the values specified there to recognise if the file is a binary XLS.
You can validate file type by adding nested try..catch.. clause.
try
{
//open connnection for x file
}catch(Exception ex)
{
try
{
//open connection for y file
}catch(...)
{
}
}
精彩评论