using System.Io;
private void saveFileToFolder()
{
try
{
string filepath = "";
HttpPostedFile file = fileUploadTasks.PostedFile;
FileEntity objFileEntity = new FileEntity();
if (hiddenFolderPath.Value.ToString() != "")
{
string fileExt = Path.GetExtension(file.FileName).ToLower();
int filelength = file.ContentLength;
string fileName = Path.GetFileName(file.FileName);
FileEntity objFile = objDocumentBusinessFacade.CheckExistingFileNameByFolderID(Convert.ToInt32(hdnFolderSelectionCount.Value), fileName);
if (objFile.FileID == 0)
{
if (fileName != string.Empty)
{
if (filelength < 1048576)
{
if (fileExt == ".txt" || fileExt == ".rtf" || fileExt == ".doc" || fileExt == ".docx" || fileExt == ".xls" || fileExt == ".xlsx" || fileExt == ".pdf" || fileExt == ".htm" || fileExt == ".html" || fileExt == ".ppt" || fileExt == ".pptx")
{
filepath = hiddenFolderPath.Value.ToString() + "/" + fileName;
file.SaveAs(Server.MapPath(hiddenFolderPath.Value.ToString() + "/") + fileName);
objFileEntity.FilePath = filepath;
objFileEntity.FileName = fileName;
objFileEntity.FolderID = int.Parse(hiddenFolderID.Value);
objDocumentBusinessFacade.InsertIntoFileandDocuments(objFileEntity);
}
else
{
lblErrorMessage.Text = "Invalid file format!";
}
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "AlertIndex", "alert('File size cannot exceed 1MB(1048576 bytes) ');", true);
return;
}
}
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "AlertIndex", "alert('Given file name already exists in this folder');", true);
return;
}
}
}
catch (Exception ex)
{
bool blnThrow = ExceptionPolicy.HandleException(ex, "WebUI");
if (blnThrow)
{
throw;
}
}
}