Good Morning Gaddad
This can be Achieved in the Following way
Step 1: get a File Uploader and put it in your page and Add a Button and in the Button that is where you will tell your Page to start using the File Uploading, add the Following Code in your button
protected void Button1_Click(object sender, EventArgs e)
{
//Check the Filetype
String sFiletype;
String sFinenames = UP.FileName;
sFiletype = Path.GetExtension(sFinenames);
sFiletype = sFiletype.ToLower();
//This Varible is assign to a Check Function that will tell us if the file has been uploaded and its a Correct file
Boolean CheckBool = Check_Rules_Before_Upload(sFiletype, UP);
if (CheckBool == false)
{
lblMessage.Text = "Select a file!";
}
else
{
BLL.BLL obj = new BLL.BLL();
String sFilename = UP.FileName;
String File_Path = @"C:\Properties_Imports" + @"\" + sFilename;
int Results = 0;
try
{
Results = obj.Import_Data_Properties(File_Path, Convert.ToString(Session["ActiveDatabase"]));
if (Results == 1)
{
lblMessage.Text = "Successfully Imported";
}
else
{
lblMessage.Text = "Import Error, Please Make sure that There are no Duplicates in the TBLResource table";
}
}
catch (SqlException ex)
{
lblMessage.Text = ex.Message;
}
}
}
Add another Function that will be used to check the Extensions
//This Function to check the Rules if they are not Broken. We cannot not Upload invalid Files
private Boolean Check_Rules_Before_Upload(String FileExtension, FileUpload FileUploadControl)
{
Boolean Bolres = false;
if (FileExtension == ".xml" && UP.HasFile)
{
Bolres = true;
}
else
{
Bolres = false;
}
return Bolres;
}
as you can see i was testing for XML and you can add as many extensions as you want.
Thank you again for Posting at Dotnetfunda
Vuyiswa Maseko
Thank you for posting at Dotnetfunda
[Administrator]
Gaddad, if this helps please login to Mark As Answer. | Alert Moderator