Example Please?

4 posts, 0 answers
  1. Aaron
    Aaron avatar
    5 posts
    Member since:
    Dec 2011

    Posted 24 Sep 2012 Link to this post

    Can you please give me an ASP.NET 4.0 VB.NET example of uploading to /images/post/ directory and renaming the image to a session value - with a 1, 2, 3, 4 etc saved after each file name?  The 1, 2, 3, 4 is just used to signify different images or else the images would just overwrite each other.

    I will only be upload .jpg images!

    Thanks!
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 25 Sep 2012 Link to this post

    Hi Aaron,

    Try the following code to achieve your scenario.

    protected void RadAsyncUpload1_FileUploaded(object sender, Telerik.Web.UI.FileUploadedEventArgs e)
        {
            string targetFolder = RadAsyncUpload1.TargetFolder;
            int cnt = Convert.ToInt16(Session["value"].ToString());
            string newName = "newName"+cnt.ToString();
            e.File.SaveAs(Path.Combine(Server.MapPath(targetFolder), newName + e.File.GetExtension()));
            Session["value"] = ++cnt;
        }

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Aaron
    Aaron avatar
    5 posts
    Member since:
    Dec 2011

    Posted 25 Sep 2012 Link to this post

    Isnt that resetting my session value at the end?

    Session["value"] = ++cnt;
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 26 Sep 2012 Link to this post

    Hi Aaron,

    In the beginning of a session you can get the value from the Database and store it in the session. In each file upload you can get the value from the session for saving the file and increment the session value.

    Hope this helps.

    Thanks,
    Princy.
Back to Top