This is a migrated thread and some comments may be shown as answers.

Asyncupload Rename File

1 Answer 338 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Allan
Top achievements
Rank 2
Allan asked on 08 Aug 2012, 12:26 AM
I just can't seem to get renaming a file during upload to work. I have tried to follow all the examples including the one here:http://www.telerik.com/community/forums/aspnet-ajax/upload/renaming-file-with-custom-progress.aspx

Here is the code I currently have:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="radup.aspx.vb" Inherits="radup" %>
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
 
        <telerik:radcodeblock id="RadCodeBlock1" runat="server">
 
        <script type="text/javascript">
 
            var $ = $telerik.$;
 
            function onClientFileUploaded(radAsyncUpload, args) {
                var $row = $(args.get_row());
                var inputName = radAsyncUpload.getAdditionalFieldID("TextBox");
                var inputType = "text";
                var inputID = inputName;
                var input = createInput(inputType, inputID, inputName);
                var label = createLabel(inputID);
                $row.append("<br/>");
                $row.append(label);
                $row.append(input);
            }
 
            function createInput(inputType, inputID, inputName) {
                var input = '<input type="' + inputType + '" id="' + inputID + '" name="' + inputName + '" />';
                return input;
            }
 
            function createLabel(forArrt) {
                var label = '<label for=' + forArrt + '>File info: </label>';
                return label;
            }
 
        </script>
 
    </telerik:radcodeblock>
     
    <div>
     
        <br />
         
        <telerik:RadAsyncUpload runat="server" id="RadAsyncUpload1" TargetFolder="~/upload" OnClientFileUploaded="onClientFileUploaded"></telerik:RadAsyncUpload>
         
        <br />
        <asp:Button ID="Button1" runat="server" Text="Button" />
        <br />
     
    </div>
    <telerik:RadScriptManager ID="RadScriptManager1" Runat="server">
    </telerik:RadScriptManager>
    </form>
</body>
</html>


Imports System
Imports System.IO
Imports System.Collections
Imports System.Data
Imports System.Data.SqlClient
Imports Telerik.Web.UI
 
Partial Class radup
    Inherits System.Web.UI.Page
 
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
 
        For Each f As UploadedFile In RadAsyncUpload1.UploadedFiles
            Dim fileName As String = Guid.NewGuid().ToString + f.GetName()
            Dim title As String = f.GetFieldValue("TextBox")
 
            f.SaveAs(fileName & ".XML", True)
        Next
    End Sub
 
End Class

Here is my error:

Could not find file 'C:\Websites\edibletastyprints\htdocs\App_Data\RadUploadTemp\0bbbftff.g4z'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileNotFoundException: Could not find file 'C:\Websites\edibletastyprints\htdocs\App_Data\RadUploadTemp\0bbbftff.g4z'.

Source Error:

Line 15:             Dim title As String = f.GetFieldValue("TextBox")
Line 16:
Line 17:             f.SaveAs(fileName & ".XML", True)
Line 18:             Response.Redirect("uploadsuccess.aspx?fileName=" & fileName & "&title=" & title)
Line 19:         Next
 

Source File: C:\Websites\edibletastyprints\htdocs\radup.aspx.vb    Line: 17

Stack Trace:

[FileNotFoundException: Could not find file 'C:\Websites\edibletastyprints\htdocs\App_Data\RadUploadTemp\0bbbftff.g4z'.]
   System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +9718655
   System.IO.File.Move(String sourceFileName, String destFileName) +239
   Telerik.Web.UI.AsyncUploadedFile.SaveAs(String fileName, Boolean overwrite) +50
   radup.Button1_Click(Object sender, EventArgs e) in C:\Websites\edibletastyprints\htdocs\radup.aspx.vb:17
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563

 
As always, any help much appreciated.

1 Answer, 1 is accepted

Sort by
0
Peter Filipov
Telerik team
answered on 10 Aug 2012, 11:00 AM
Hi Allan,

I setup a working page from your sample code, please review the attachment. Keep in mind that when you manually save the files the TargetFolder property should not be set.

 Regards,
Peter Filipov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
AsyncUpload
Asked by
Allan
Top achievements
Rank 2
Answers by
Peter Filipov
Telerik team
Share this question
or