I upload documents to a temporary folder using the Upload Control FileUploadComplete event, but I try to control what is uploaded to the temporary folder, so I can move it to the real application folder when the submit button is pressed,
I will upload the code that I have; hope some of them are helpful, thanks
protected List<string> listTempImages = new List<string>();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ucUploadFile_FileUploadComplete(object sender, FileUploadCompleteEventArgs e)
{
e.CallbackData = SavePostedFiles(e.UploadedFile);
}
string SavePostedFiles(UploadedFile uploadedFile)
{
if (!uploadedFile.IsValid)
{
return string.Empty;
}
string strAttachmentFolderQuery = "CALL storedProcedure";
DataTable dtFolderLocation = new DataTable();
BasicUtilities.SelectCommand(ref strAttachmentFolderQuery, ref dtFolderLocation, sqlConn, true);
string strFolderLocation = @dtFolderLocation.Rows[0]["ColumnName"].ToString();
string strCallFolder = strFolderLocation + @"Temp\\";
listTempImages.AddRange(uploadedFile.FileName.Split('.'));
string strFileName = listTempImages[0];
FileInfo fi = new FileInfo(strFileName);
String timeStamp;
timeStamp = DateTime.Now.ToString("yyyMMddhhmmss");
string fullFileName = MapPath(strFolderLocation) + fi.Name;
ucUploadFile.SaveAs(strCallFolder + fi.Name + "_" + timeStamp + "." + listTempImages[1]);
string fileLabel = fi.Name;
string fileLength = uploadedFile.FileContent.Length / 1024 + "k";
listTempImages.Add(strCallFolder + fi.Name + "_" + timeStamp);
return string.Format("{0} ({1})|{2}", fileLabel, fileLength, fi.Name);
}
protected void btnSubmit_Click1(object sender, EventArgs e)
{
if (listTempImages != null)
{
while (listTempImages.Count >0)
{
Upload(callID, reporterID);
}
}
else
{
}
}
** EDIT
<dx:ASPxButton ID="btnSubmit" runat="server" Text="Submit"
ClientIDMode="AutoID"
onclick="btnSubmit_Click1" AutoPostBack="False">
<ClientSideEvents Click="function(s, e) {
if(document.getElementById('ucUploadFile_Input_0') == null){
e.processonserver = false;
$('#ucUploadFile_Add').click();
e.processonserver = true;
}
}" />
</dx:ASPxButton>
source
share