Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7489247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:13:12+00:00 2026-05-29T15:13:12+00:00

I am trying to use sessions for the first time and would like to

  • 0

I am trying to use sessions for the first time and would like to know abt that in a better and easy way.

I am creating a session variable using GUID and creating a folder with that GUID and storing that value as shown below

 If Session("tempDir") Is Nothing Then
        Dim tempDir As String
        tempDir = Path.GetRandomFileName()
        tempDir = tempDir.Substring(0, tempDir.LastIndexOf("."))
        IO.Directory.CreateDirectory(Server.MapPath("Uploads/" & tempDir))
        IO.Directory.CreateDirectory(Server.MapPath("Downloads/" & tempDir))
        Session.Add("tempDir", tempDir)
        currentDirectory.Value = Session("tempDir").ToString
        CopySession.Text = currentDirectory.Value
    End If

This is the code for generating GUID:

 function randomString(length) {
            var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'.split('');

            if (!length) {
                length = Math.floor(Math.random() * chars.length);
            }

            var str = '';
            for (var i = 0; i < length; i++) {
                str += chars[Math.floor(Math.random() * chars.length)];
            }
            return str;
        }

I am using the below code to get that on page is postback but whenver I refreshes it deletes that value and gives me a NULL value.

If Page.IsPostBack Then
            If Session("tempDir") Is Nothing Then
                Dim tempDir As String
                tempDir = Path.GetRandomFileName()
                tempDir = tempDir.Substring(0, tempDir.LastIndexOf("."))
                IO.Directory.CreateDirectory(Server.MapPath("Uploads/" & tempDir))
                IO.Directory.CreateDirectory(Server.MapPath("Downloads/" & tempDir))
                Session.Add("tempDir", tempDir)
                currentDirectory.Value = Session("tempDir").ToString
                CopySession.Text = currentDirectory.Value

            End If
End If

How do I retrieve the tempDir value?Can anyone give me some detailed explanation regarding this as I am totally confusing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T15:13:13+00:00Added an answer on May 29, 2026 at 3:13 pm

    Remove this 2 lines out of the IF

            currentDirectory.Value = Session("tempDir").ToString
            CopySession.Text = currentDirectory.Value
    

    will be

    If Page.IsPostBack Then
                If Session("tempDir") Is Nothing Then
                    Dim tempDir As String
                    tempDir = Path.GetRandomFileName()
                    tempDir = tempDir.Substring(0, tempDir.LastIndexOf("."))
                    IO.Directory.CreateDirectory(Server.MapPath("Uploads/" & tempDir))
                    IO.Directory.CreateDirectory(Server.MapPath("Downloads/" & tempDir))
                    Session.Add("tempDir", tempDir)
                End If
    
                currentDirectory.Value = Session("tempDir").ToString
                CopySession.Text = currentDirectory.Value
    End If
    

    What Is the different here, that if the session is not exist, then go and set it it. After the if the session for tempDir exist because ether you just set it, ether get it from previous or other call. I hope this give you what you wondering, or else tell me what you do not understand.

    Session

    The session is a Dictionary of values that is connected with each user for the time the session is active (eg for 20 minutes). As the user interacts with the site this data is follow this user and you can set them, read them or delete them using the session.
    When a page loads the session data read at the start, you can used them on page, and on page unload the session data saved back to session keeper.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have used sessions before but never cookies. I would like to use cookies
I'm trying to use the built-in .NET session handling to share sessions across multiple
This is my first time trying to use the XMLRPC::Client library to interact with
This is my first time trying to use any SCM so please bear with
I'm trying to use Entity Framework for the first time, and have come a
We are trying to use nHibernate first time in my project in VS2010 and
Its y first time trying to use NSData and Gamekit. So was wondering am
I am trying to use PHP session without using cookies. I have enabled session.use_trans_sid
I am trying to use it for Login page. if (Session[UserID] == null) Server.Transfer(/Account/Login,
How to get Hibernate session inside a Hibernate Interceptor? I'm trying to use Hibernate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.