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

Uploader naming files with client's file path

2 Answers 81 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Glenn Boothe
Top achievements
Rank 1
Glenn Boothe asked on 13 Feb 2009, 09:22 PM
I can't recreate this issue, but it's been happening with my applications.  Files are being named by the path of the uploaded file on the client's machine.  For example, radUpload is trying to save an uploaded file to ~/casefiles/\\S001\scans\filename.pdf from the code below:

in .aspx:
            <telerik:RadUpload runat="server" ID="Radupload1" TargetFolder="~/casefiles" InitialFileInputsCount="3"
            OverwriteExistingFiles="false" OnFileExists="RadUpload1_FileExists" Skin="Skin" EnableEmbeddedSkins="false" />

In .aspx.vb

    Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
            If Radupload1.UploadedFiles.Count > 0 Then
                lblConfirm.Text = "File upload successfully,"
            Else
                lblError.Text = "Please choose at least one file to upload."
            End If
    End Sub

    Protected Sub RadUpload1_FileExists(ByVal sender As Object, ByVal e As Telerik.Web.UI.Upload.UploadedFileEventArgs)
        Dim counter As Integer = 1
        Dim file As UploadedFile = e.UploadedFile
        Dim targetFolder As String = Server.MapPath(RadUpload1.TargetFolder)
        Dim targetFileName As String = Path.Combine(targetFolder, file.GetNameWithoutExtension() + counter.ToString() + file.GetExtension())
        While System.IO.File.Exists(targetFileName)
            System.Math.Max(System.Threading.Interlocked.Increment(counter), counter - 1)
            targetFileName = Path.Combine(targetFolder, file.GetNameWithoutExtension() + counter.ToString() + file.GetExtension())
        End While
        file.SaveAs(targetFileName)
    End Sub

2 Answers, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 17 Feb 2009, 07:24 AM
Hi Glenn Boothe,

I reviewed your code, but i did not manage to find any problems with it at all. Could you please be more specific in  what is going wrong? As I have tested, uploaded files are being saved without  a problem, even if I use the same file several times. An incremented number is appended to each file name, thus no overwrite occurs.

For your convenience I have attached the project I tested.

Greetings,
Genady Sergeev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Glenn Boothe
Top achievements
Rank 1
answered on 17 Feb 2009, 12:26 PM
Genady,  Thanks for the response,

Like I said, I couldn't recreate the issue either.  Every test I ran was perfect.  However after toying with it for a while I worked it out for the client like this:

ASPX:
    <telerik:RadUpload runat="server" ID="Radupload1" InitialFileInputsCount="3"
    OverwriteExistingFiles="false" OnFileExists="RadUpload1_FileExists" Skin="Skin" EnableEmbeddedSkins="false" />

ASPX.VB:
    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
            If Radupload1.UploadedFiles.Count > 0 Then

                For Each f As UploadedFile In Radupload1.UploadedFiles
                    f.SaveAs(Server.MapPath("../casefiles/") & f.GetName)
                Next

                lblConfirm.Text = "File upload successful."
            Else
                lblError.Text = "Please choose at least one file to upload."
            End If
    End Sub

I took the target folder out and "manually" uploaded the files with the for each statement.

It was as if the radUploader was using the UploadedFile.FileName (which returns the path as well?) to name the file, not the .GetName.  The only extra information I know is that the client was trying to upload the file from a local network path.  If I find out more, I'll post.

Thanks
Tags
Upload (Obsolete)
Asked by
Glenn Boothe
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
Glenn Boothe
Top achievements
Rank 1
Share this question
or