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

RadUpload In Window Saving Twice

2 Answers 124 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 18 Feb 2008, 09:33 PM
I'm using a rad window to upload some files to the server.  When I upload the first time it works, how ever if I use the same form and upload a second time, it saves the file twice in the target folder.  Once with the name I give in in the function below and the other file is without the appended documentid.  So i get two files like this: 143test.txt and test.txt.


Here is my bindresults function that is called on the sumbit click.  Any ideas?  Its as if the inital save uses the default temp folder and then on subsequent saves it changes the temp folder to the targetphysical path.

    private void BindResults()
    {
        thisUser = new User(SessionHandler.UserID);

        string folderpath = ConfigurationManager.AppSettings["AttachmentsLocation"].ToString();
        RadUpload1.TargetPhysicalFolder = folderpath;
        string targetFileName = "";
        foreach (UploadedFile f in RadUpload1.UploadedFiles)
        {
            string ext = f.GetExtension().Replace(".", "");
            int size = f.ContentLength;
            double fsize = Convert.ToDouble(size) / 1000;
            Int32 docid = DataAccess.SaveDocument(thisUser.UserID, f.FileName, ext, "", fsize);
            targetFileName = Path.Combine(folderpath, docid.ToString() + f.FileName);
            f.SaveAs(targetFileName);
            int attachmentid = DataAccess.DocumentAttach(docid, Convert.ToInt32(Request.QueryString["todoid"].ToString()), AllItemTypes.ToDo);
        }
    }

2 Answers, 1 is accepted

Sort by
0
Petya
Telerik team
answered on 19 Feb 2008, 08:14 AM
Hi John,

The reason you experience this problem is that on first submit you set RadUpload1.TargetPhysicalFolder = folderpath. So, on next submit the selected file is first automatically saved because you have specified a TargetPhysicalFolder and then it gets saved by your code f.SaveAs(targetFileName). Why do you set RadUpload1.TargetPhysicalFolder? Specifying TargetPhysicalFolder/TargetFolder property activates the process of automatically saving the uploaded file to the specified folder.

Regards,
Petya
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
John
Top achievements
Rank 1
answered on 19 Feb 2008, 04:31 PM
Thanks, I wasn't sure what I was doing, but this now makes sense to me.  Thanks.
Tags
Upload (Obsolete)
Asked by
John
Top achievements
Rank 1
Answers by
Petya
Telerik team
John
Top achievements
Rank 1
Share this question
or