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 751461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:40:10+00:00 2026-05-14T14:40:10+00:00

I hope the title is not too confusing. I am trying to make folders

  • 0

I hope the title is not too confusing. I am trying to make folders with linq-to-sql objects’ IDs. Actually I have to create folders before I should save them. I will use them to keep user uploaded files. As you can see I have to create the folder with the FileID before I can save it there. So I just save a record which will be edited or maybe deleted

File newFile = new File();
...//add some values to fields so they don't throw rule violations
db.AddFile(newFile);
db.Save();
System.IO.Directory.CreateDirectory("..Uploads/"+newFile.FileId.ToString());

After that I will have to edit some fields and save again. Of course user might stop upload and I would have to delete it. I know I can write a stored procedure to get the next available FileID but some other upload happening at the same time would get the same number. So they would write in same directory which is a thing I don’t want. Should I go on with this, would there be some problems? Can you think of a better way?

  • 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-14T14:40:11+00:00Added an answer on May 14, 2026 at 2:40 pm

    Well.. one thing you could do is generate a GUID, and use that for your folder name instead

    string uniqueDirectory = System.Guid.NewGuid().ToString("N");
    System.IO.Directory.CreateDirectory("..Uploads/"+uniqueDirectory );
    //handle upload, save file, errors,  etc..
    ...
    //now that the file is uploaded save to the database
    File newFile = new File();
    newFile.FolderName=uniqueDirectory;
    db.AddFile(newFile);
    db.Save();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hope my title is not too confusing. Please let me know if there is
Hope the title wasn't too confusing. I have a directory full of files which
I hope the title doesn't sound too subjective; I absolutely do not mean to
I hope the title isn't too confusing, I'll try to explain better below. Suppose
I hope the title is not mis-leading. I am trying to implement onRetainNonConfigurationInstance() of
Hope the title is not that confusing - honestly said I had no idea
I hope the title is not too misleading... :) I play a system sound
I hope the title explains what I'd like to achieve. If not, please read
I hope the title and following text are clear, I'm not very familiar with
I hope the title actually describes what I wanted to ask... I wrote a

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.