How to upload these PPT/PPS/Doc/Pdf/xls Content files to the web server using asp.net/c#?

Posted by Gaddad under ASP.NET on 6/11/2009 | Views : 4168 | Status : [Member] | Replies : 2
I want to upload files like PPT/PPS/Doc/Pdf/xls Content to the web server using .net applications.

Thanks in advance.




Responses

Posted by: Raja on: 6/11/2009 [Member] Starter

Up
0
Down
Irrespective of any extension like PPT, PPS , you can upload any kind of file on the server. At the server side you can validate if you want for specific file extension.

You can use following tutorial to do that

http://www.dotnetfunda.com/tutorials/controls/fileupload.aspx

Also you can use this

http://www.dotnetfunda.com/codes/code64-how-to-upload-files-in-asp-net.aspx

Thanks

Regards,
Raja, USA

Gaddad, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 6/11/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
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

Login to post response