Hi All,
At some point I've had this working but I've changed a few things around and I seem to have broken it!
I have the following code in my .aspx page:
I have this in my code-behind (C#)
The 'if' block of my code works fine but for some reason however, my 'File' variable in my else block is always null and throws the exception (which I'm not handling very gracefully at the minute!).
If I hover over UploadContext.UploadedFiles, there is a file in the collection with the correct name, mime type etc.
Any ideas why File is always null?
Thanks in advance,
Brett
At some point I've had this working but I've changed a few things around and I seem to have broken it!
I have the following code in my .aspx page:
<radU:RadUpload ID="RadUpload1" runat="server" MaxFileInputsCount="1" /> | |
<radU:RadProgressArea ID="RadProgressArea1" runat="server" Skin="Vista"> | |
</radU:RadProgressArea> | |
<radU:RadProgressManager ID="RadProgressManager1" runat="server" /> | |
<asp:Button ID="UploadButton" runat="server" Text="Upload File" OnClick="UploadButton_Click" /> |
I have this in my code-behind (C#)
protected void Page_Load(object sender, EventArgs e) | |
{ | |
// Only display the input for the upload control | |
RadUpload1.ControlObjectsVisibility = ControlObjectsVisibility.None; | |
RadUpload1.AllowedFileExtensions = new string[] { ".csv" }; | |
// Get QS into a string and populate label control | |
string CampaignName = Request.QueryString["CampaignName"]; | |
CampaignNameLabel.Text = CampaignName; | |
} | |
protected void UploadButton_Click(object sender, EventArgs e) | |
{ | |
try | |
{ | |
//an invalid file has tried to upload... | |
if (RadUpload1.InvalidFiles.Count > 0) | |
{ | |
lblFileUploaded.Visible = true; | |
lblFileUploaded.ForeColor = System.Drawing.Color.Red; | |
lblFileUploaded.Text = "The file format is not valid. Please upload a CSV file."; | |
} | |
else | |
{ | |
RadUploadContext UploadContext = RadUploadContext.Current; | |
UploadedFile File; | |
File = UploadContext.UploadedFiles[RadUpload1.UniqueID]; | |
File.SaveAs(Server.MapPath(@"C:\Temp\RADUpload\" + CampaignNameLabel.Text + "_Targets.csv")); | |
lblFileUploaded.Visible = true; | |
lblFileUploaded.ForeColor = System.Drawing.Color.Black; | |
lblFileUploaded.Text = "Your targets have been uploaded successfully."; | |
} | |
} | |
catch (Exception ex) | |
{ | |
throw; | |
} | |
} |
The 'if' block of my code works fine but for some reason however, my 'File' variable in my else block is always null and throws the exception (which I'm not handling very gracefully at the minute!).
If I hover over UploadContext.UploadedFiles, there is a file in the collection with the correct name, mime type etc.
Any ideas why File is always null?
Thanks in advance,
Brett