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

Upload file, process it, display results

4 Answers 226 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Veteran
Matt asked on 16 Jan 2020, 10:01 PM

ASPX:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TelerikUpload.aspx.cs" Inherits="ImportMPV2_WebTest.TelerikUpload" %>
 
<!DOCTYPE html>
 
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
        <div>
            <telerik:RadAsyncUpload
                AllowedFileExtensions="xlsx"
                EnableInlineProgress="true"
                ID="RadAsyncUpload1"
                MaxFileInputsCount="1"
                MultipleFileSelection="Disabled"
                OnFileUploaded="RadAsyncUpload1_FileUploaded"
                RenderMode="Lightweight"
                runat="server"
                Skin="Telerik"
                TargetDir="Uploads">
                <FileFilters>
                    <telerik:FileFilter Description="Excel Files(xlsx)" Extensions="xlsx" />
                </FileFilters>
            </telerik:RadAsyncUpload>
        </div>
        <br />
        <telerik:RadButton AutoPostBack="true" runat="server" Text="Import" Skin="Telerik" />
    </form>
 
    <pre>
<asp:label id="lblUploadResults" runat="server"></asp:label>
    </pre>
    <pre>
<asp:label id="lblSSISResults" runat="server"></asp:label>
    </pre>
 
</body>
</html>

 

Code behind:

protected void RadAsyncUpload1_FileUploaded(object sender, FileUploadedEventArgs e)
{
    UploadedFile uploadFile = e.File;
    string xlFilePath = Path.Combine(Server.MapPath(WebConfigurationManager.AppSettings["uploadDir"]), uploadFile.FileName);
 
    // Display upload results
    lblUploadResults.Text = "File Uploaded\n"
        + "File name: " + uploadFile.FileName + "\n"
        + "Content type: " + uploadFile.ContentType + "\n"
        + "Content length: " + uploadFile.ContentLength + "\n"
        + "Last modified date: " + uploadFile.LastModifiedDate + "\n";
 
    // Execute SSIS package
    SSISExecutor ssisExecutor = new SSISExecutor(
        xlFilePath
        , "Balance Import"
        , "gregorym"
        , false
        , WebConfigurationManager.AppSettings["logFilePath"]
        , WebConfigurationManager.ConnectionStrings["DatabasePEP1"].ConnectionString
        );
    ssisExecutor.Exec(out List<string> resultList);
 
    // Display SSIS results
    string s = "SSIS results:\n" + xlFilePath + ":\n\n";
    foreach (string result in resultList)
    {
        s += result + "\n";
    }
    lblSSISResults.Text = s;
}

 

Output:

File Uploaded
File name: ImportV2_Sample.xlsx
Content type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Content length: 326210
Last modified date: 1/13/2020 4:47:40 PM
 
     
SSIS results:
C:\ImportMPV2_WebTest\Uploads\ImportV2_Sample.xlsx:
 
Error: File "C:\ImportMPV2_WebTest\Uploads\ImportV2_Sample.xlsx" not found

 

 

 

 

4 Answers, 1 is accepted

Sort by
0
Matt
Top achievements
Rank 1
Veteran
answered on 16 Jan 2020, 10:06 PM
Can't edit my post.  My question is:  Why can't my processing routine access the file?
0
Matt
Top achievements
Rank 1
Veteran
answered on 16 Jan 2020, 10:09 PM

If I add an upload handler to copy it, it will work, but that seems dumb.  Now there are duplicate file on the system, and the code just does what the Telerik code already does, it just changes the timing of it so the file gets copied earlier.  I'm also supposed to delete these files when processing is done, but that is also difficult.

 

protected override IAsyncUploadResult Process(UploadedFile file, HttpContext context, IAsyncUploadConfiguration configuration, string tempFileName)
{
    string uploadDir = context.Server.MapPath(WebConfigurationManager.AppSettings["uploadDir"]);
    using (FileStream outFile = File.Create(Path.Combine(uploadDir, file.FileName)))
    {
        file.InputStream.Seek(0, SeekOrigin.Begin);
        file.InputStream.CopyTo(outFile);
    }
    return base.Process(file, context, configuration, tempFileName);
}
0
Peter Milchev
Telerik team
answered on 21 Jan 2020, 01:05 PM

Hello Matt,

Would you please provide more details about what exactly is the end goal and why accessing the file via e.File in FileUploaded does not work for you? 

Also, you can check the following article showing how the temporary file can be accessed and optionally removed:

Regards,
Peter Milchev
Progress Telerik

Get quickly onboarded and successful with UI for ASP.NET AJAX with the Virtual Classroom technical trainings, available to all active customers. Learn More.
0
Matt
Top achievements
Rank 1
Veteran
answered on 22 Jan 2020, 05:49 PM

Hi Peter,

Thanks for the reply.  Sorry about the unclear post.  I have very scant experience with web forms, so I'm in a state of confusion all around.  I'm in the process of writing a demo page that incorporates the upload control.

Thanks for that link.  I think that might be all I need.

Matt

Tags
AsyncUpload
Asked by
Matt
Top achievements
Rank 1
Veteran
Answers by
Matt
Top achievements
Rank 1
Veteran
Peter Milchev
Telerik team
Share this question
or