Hi,
I'm have a page called FileManager.aspx that is calling another page called FileUpload.aspx in a RadWindow.
The FileUpload.aspx (in a RadWindow) has one asp:Button (uxFileUploadReturnButton) that submits the form and has a OnClick event named FileUploadReturnButton_Click .
In this click event, it iterates through the UploadedFiles (UploadedFileCollection) and does several business logic - one of which is to use the SaveAs method to save the file in a different file name (GUID in my case).
However, when doing the above, I encountered an error saying that the "temporary file" cannot be found.
When debugging, I notice that upon reaching my click event handler in my presenter class, the files has already been moved over to the Target Folder - with their original file names.
I'm not certain where the problem is to achieve using the SaveAs method in my asp.net web application.
Note: I've registered the Panel which contains the AsynchUpload control to the RadAjaxManager.
Note: I'm using RadControls version 2010.1 309 in VS 2008 SP1
FileMangager.aspx
FileUpload.aspx
FileUpload.aspx.cs
FileUploadPresenter.cs (class library)
Error Message
System.IO.FileNotFoundException was caught
Message="Could not find file 'C:\\Dev\\App_Data\\TemporaryFiles\\1lsi1z34.y5v'."
Source="mscorlib"
FileName="C:\\Dev\\App_Data\\TemporaryFiles\\1lsi1z34.y5v"
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.Move(String sourceFileName, String destFileName)
at Telerik.Web.UI.AsyncUploadedFile.SaveAs(String fileName, Boolean overwrite)
at Dev.FileUploadPresenter.FileUploadSaveFilesButtonClickEventHandler(Object sender, EventArgs e) in C:\Dev\FileUploadPresenter.cs:line 125
Many Thanks,
Henry Wu
I'm have a page called FileManager.aspx that is calling another page called FileUpload.aspx in a RadWindow.
The FileUpload.aspx (in a RadWindow) has one asp:Button (uxFileUploadReturnButton) that submits the form and has a OnClick event named FileUploadReturnButton_Click .
In this click event, it iterates through the UploadedFiles (UploadedFileCollection) and does several business logic - one of which is to use the SaveAs method to save the file in a different file name (GUID in my case).
However, when doing the above, I encountered an error saying that the "temporary file" cannot be found.
When debugging, I notice that upon reaching my click event handler in my presenter class, the files has already been moved over to the Target Folder - with their original file names.
I'm not certain where the problem is to achieve using the SaveAs method in my asp.net web application.
Note: I've registered the Panel which contains the AsynchUpload control to the RadAjaxManager.
Note: I'm using RadControls version 2010.1 309 in VS 2008 SP1
FileMangager.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Dev/AccountLayout.master" AutoEventWireup="true" CodeBehind="FileManager.aspx.cs" Inherits="Dev.FileManager" %> |
<asp:Content ID="uxFileManagerContentContainerContent" ContentPlaceHolderID="uxAccountLayoutContentContainerContentPlaceHolder" runat="server"> |
<asp:Button ID="Button1" runat="server" Text="Upload Files" /> |
<telerik:RadWindow ID="RadWindow2" runat="server" OpenerElementId="<%# Button1.ClientID %>" NavigateUrl="~/FileUpload/" |
AutoSize="false" Behaviors="Close" DestroyOnClose="true" KeepInScreenBounds="true" Modal="true" |
RegisterWithScriptManager="true" Title="Upload File" VisibleStatusbar="false" Width="600" Height="350"> |
</telerik:RadWindow > |
</asp:Content> |
FileUpload.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Dev/WindowLayout.master" AutoEventWireup="true" CodeBehind="FileUpload.aspx.cs" Inherits="Dev.FileUpload" Theme="Default" %> |
<asp:Content ID="uxFileUploadContentContainerContent" ContentPlaceHolderID="uxWindowLayoutContentContainerContentPlaceHolder" runat="server"> |
<div id="uxFileUploadContainerWrapperDiv"> |
<div id="uxFileUploadContainerDiv"> |
<asp:Panel ID="uxFileUploadContainerPanel" runat="server"> |
<div id="uxFileUploadHeaderWrapperDiv"> |
<div id="uxFileUploadHeaderDiv"> |
<asp:Panel ID="uxFileUploadBeginUploadHeaderPanel" CssClass="cssFileUploadBeginUploadHeaderPanel" runat="server" Visible="true"> |
<h1> |
<asp:Label ID="uxFileUploadBeginUploadTitleLabel" CssClass="cssFileUploadBeginUploadTitleLabel" runat="server" Text="Upload to My Files"></asp:Label> |
</h1> |
</asp:Panel> |
<asp:Panel ID="uxFileUploadEndUploadHeaderPanel" CssClass="cssFileUploadEndUploadHeaderPanel" runat="server" Visible="false"> |
<h1> |
<asp:Label ID="uxFileUploadEndUploadTitleLabel" CssClass="cssFileUploadEndUploadTitleLabel" runat="server" Text="Upload Complete"></asp:Label> |
</h1> |
</asp:Panel> |
</div> |
</div> |
<div id="uxFileUploadContentWrapperDiv"> |
<div id="uxFileUploadContentDiv"> |
<asp:Panel ID="uxFileUploadBeginUploadContentPanel" CssClass="cssFileUploadBeginUploadContentPanel" runat="server" Visible="true"> |
<telerik:RadProgressManager ID="uxFileUploadRadProgressManager" runat="server" EnableMemoryOptimization="true" RegisterWithScriptManager="true" /> |
<div id="uxFileUploadFileListHeaderDiv"> |
<div id="uxFileUploadFileNameColumnDiv"> |
<asp:Label ID="uxFileUploadFileNameColumnLabel" runat="server" Text="File Name"></asp:Label> |
</div> |
<div id="uxFileUploadRemoveColumnDiv"> |
<asp:Label ID="uxFileUploadRemoveColumnLabel" runat="server" Text="Remove?"></asp:Label> |
</div> |
</div> |
<div id="uxFileUploadFileListContainerDiv" class="cssFileUploadFileListContainerDiv"> |
<telerik:RadAsyncUpload ID="uxFileUploadRadAsyncUpload" CssClass="cssFileUploadRadAsyncUpload" runat="server" AutoAddFileInputs="true" |
ControlObjectsVisibility="None" EnableFileInputSkinning="true" FocusOnLoad="true" Localization-Select="Add File" |
ReadOnlyFileInputs="true" OnFileUploaded="FileUploadRadAsyncUpload_FileUploaded" RegisterWithScriptManager="true"> |
</telerik:RadAsyncUpload> |
<telerik:RadProgressArea ID="uxFileUploadRadProgressArea" CssClass="cssFileUploadRadProgressArea" runat="server" RegisterWithScriptManager="true" |
ProgressIndicators="FilesCountBar,FilesCount,FilesCountPercent,SelectedFilesCount,CurrentFileName,TimeElapsed,TimeEstimated"> |
</telerik:RadProgressArea> |
</div> |
<div id="uxFileUploadFileListFooterDiv"> |
<div id="uxFileUploadTotalsDiv"> |
<asp:Label ID="uxFileUploadTotalLabel" CssClass="cssFileUploadTotalLabel" runat="server" Text="Total:"></asp:Label> |
<asp:Label ID="uxFileUploadFileCountLabel" CssClass="cssFileUploadFileCountLabel" runat="server" Text="0"></asp:Label> |
<asp:Label ID="uxFileUploadUnitFileLabel" CssClass="cssFileUploadUnitFileLabel" runat="server" Text="files,"></asp:Label> |
<asp:Label ID="uxFileUploadFileSizeLabel" CssClass="cssFileUploadFileSizeLabel" runat="server" Text="0"></asp:Label> |
<asp:Label ID="uxFileUploadUnitSizeLabel" CssClass="cssFileUploadUnitSizeLabel" runat="server" Text="MB"></asp:Label> |
</div> |
<br /> |
</div> |
<div id="uxFileUploadUserActionDiv" class="cssFileUploadUserActionDiv"> |
<asp:Button ID="uxFileUploadSaveFilesButton" runat="server" Text="Save Uploaded Files" OnClick="FileUploadSaveFilesButton_Click" /> |
</div> |
</asp:Panel> |
<asp:Panel ID="uxFileUploadEndUploadContentPanel" CssClass="cssFileUploadEndUploadContentPanel" runat="server" Visible="false"> |
<asp:Label ID="uxFileUploadEndUploadMessageLabel" CssClass="cssFileUploadEndUploadMessageLabel" runat="server" Text="Your upload was completed successfully."></asp:Label> |
<asp:Button ID="uxFileUploadReturnButton" CssClass="cssFileUploadReturnButton" runat="server" Text="Return to My Files" OnClick="FileUploadReturnButton_Click" /> |
</asp:Panel> |
</div> |
</div> |
<div id="uxFileUploadFooterWrapperDiv"> |
<div id="uxFileUploadFooterDiv"> |
</div> |
</div> |
</asp:Panel> |
</div> |
</div> |
</asp:Content> |
FileUpload.aspx.cs
protected void Page_Load(object sender, EventArgs e) |
{ |
if (!this.IsPostBack) |
{ |
Presenter.ViewInitializedEventHandler(sender, e); |
} |
else |
{ |
Presenter.ViewLoadedEventHandler(sender, e); |
} |
} |
protected void FileUploadSaveFilesButton_Click(object sender, EventArgs e) |
{ |
if (FileUploadSaveFilesButtonClickEventHandler != null) |
{ |
FileUploadSaveFilesButtonClickEventHandler(sender, e); |
} |
} |
FileUploadPresenter.cs (class library)
public override void ViewInitializedEventHandler(object sender, EventArgs e) |
{ |
// View initilization logic. |
ConfigureAjaxSettings(); |
ConfigureControls(); |
LoadViewData(); |
} |
public override void ViewLoadedEventHandler(object sender, EventArgs e) |
{ |
// View loaded logic. |
ConfigureAjaxSettings(); |
// Delegate view events to the presenter. |
ConfigureEventHandlers(); |
} |
private void ConfigureAjaxSettings() |
{ |
View.WindowLayoutRadAjaxManager.AjaxSettings.AddAjaxSetting(View.FileUploadSaveFilesButton, View.FileUploadBeginUploadContentPanel); |
} |
private void ConfigureEventHandlers() |
{ |
View.FileUploadSaveFilesButtonClickEventHandler += new EventHandler<EventArgs>(FileUploadSaveFilesButtonClickEventHandler); |
View.FileUploadReturnButtonClickEventHandler += new EventHandler<EventArgs>(FileUploadReturnButtonClickEventHandler); |
View.FileUploadRadAsyncUploadFileUploadedEventHandler += new EventHandler<FileUploadedEventArgs>(FileUploadRadAsyncUploadFileUploadedEventHandler); |
} |
private void FileUploadSaveFilesButtonClickEventHandler(object sender, EventArgs e) |
{ |
string targetFolder = _configurationDefinition.FileUploadTargetFolder; |
int upperBound = View.FileUploadRadAsyncUpload.UploadedFiles.Count; |
string[] fileSystemNames = new string[upperBound]; |
string[] uploadedFileNames = new string[upperBound]; |
string[] fileTitles = new string[upperBound]; |
int[] fileSizes = new int[upperBound]; |
string[] fileContentTypes = new string[upperBound]; |
string[] fileExtensions = new string[upperBound]; |
try |
{ |
UploadedFileCollection uploadedFiles = View.FileUploadRadAsyncUpload.UploadedFiles; |
for (int index = 0; index < uploadedFiles.Count; index++) |
{ |
fileSystemNames[index] = _cryptographyService.GenerateAlphaNumericGUID(); |
uploadedFileNames[index] = uploadedFiles[index].GetName(); |
fileTitles[index] = uploadedFiles[index].GetNameWithoutExtension(); |
fileSizes[index] = uploadedFiles[index].ContentLength; |
fileContentTypes[index] = uploadedFiles[index].ContentType; |
fileExtensions[index] = uploadedFiles[index].GetExtension(); |
// Save the file as a GUID file name |
uploadedFiles[index].SaveAs(targetFolder + fileSystemNames[index]); |
} |
// Add the files to database |
_fileUploadService.AddFiles(fileSystemNames, uploadedFileNames, fileTitles, fileSizes, fileContentTypes, fileExtensions); |
// Display the File Upload Complete view |
ToggleFileUploadViews(); |
} |
catch |
{ |
try |
{ |
// For any errors delete the files that were moved to the Target Folder |
foreach (string fileSystemName in fileSystemNames) |
{ |
if (System.IO.File.Exists(targetFolder + fileSystemName)) |
{ |
System.IO.File.Delete(targetFolder + fileSystemName); |
} |
} |
} |
catch |
{ |
throw; |
} |
} |
} |
Error Message
System.IO.FileNotFoundException was caught
Message="Could not find file 'C:\\Dev\\App_Data\\TemporaryFiles\\1lsi1z34.y5v'."
Source="mscorlib"
FileName="C:\\Dev\\App_Data\\TemporaryFiles\\1lsi1z34.y5v"
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.Move(String sourceFileName, String destFileName)
at Telerik.Web.UI.AsyncUploadedFile.SaveAs(String fileName, Boolean overwrite)
at Dev.FileUploadPresenter.FileUploadSaveFilesButtonClickEventHandler(Object sender, EventArgs e) in C:\Dev\FileUploadPresenter.cs:line 125
Many Thanks,
Henry Wu