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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:56:48+00:00 2026-05-30T18:56:48+00:00

how can i make an uploading image page via razor syntax (CSHTML) to simply

  • 0

how can i make an uploading image page via razor syntax (CSHTML) to simply upload file to /image root with increasing name like imgxxxyyy.jpg when the img part is fixed and xxx is the id of the inserting/updating product and yyy is the increasing number of image of that product and store the path to the imagpath column in my table ?

more i think about it and i research about it i get more confused …. please help me in this case .

  • 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-30T18:56:49+00:00Added an answer on May 30, 2026 at 6:56 pm

    It would be easier if you used Guids for filenames. So you could define a view model:

    public class MyViewModel
    {
        [Required]
        public HttpPostedFileBase File { get; set; }
    }
    

    a view containing a form where the user will be able to select a file to upload:

    @model MyViewModel
    
    @using (Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form-data" }))
    {
        @Html.LabelFor(x => x.File)
        @Html.TextBoxFor(x => x.File, new { type = "file" })
        @Html.ValidationMessageFor(x => x.File)
        <button type="submit">Upload</button>
    }
    

    and finally a controller to show the form and process the upload:

    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View(new MyViewModel());
        }
    
        [HttpPost]
        public ActionResult Index(MyViewModel model)
        {
            if (model.File != null && model.File.ContentLength > 0)
            {
                var imageFolder = Server.MapPath("~/image");
                var ext = Path.GetExtension(model.File.FileName);
                var file = Path.ChangeExtension(Guid.NewGuid().ToString(), ext);
                var fullPath = Path.Combine(imageFolder, file);
                model.File.SaveAs(fullPath);
    
                // Save the full path of the uploaded file
                // in the database. Obviously this code should be externalized
                // into a repository but for the purposes of this example
                // I have left it in the controller
                var connString = ConfigurationManager.ConnectionStrings["MyDb"].ConnectionString;
                using (var conn = new SqlConnection(connString))
                using (var cmd = conn.CreateCommand())
                {
                    conn.Open();
                    cmd.CommandText = "INSERT INTO images VALUES (@path)";
                    cmd.Parameters.AddWithValue("@path", fullPath);
                    cmd.ExecuteNonQuery();
                }
            }
    
            return View(model);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm uploading a file to the server. The file upload HTML form has 2
I want to make a fancy image uploading system in html. When the user
Is there a way that after uploading an image from the application. I can
I am currently write a html page for uploading image, once the image gets
I want to validate the file type to make sure the user is uploading
I'm using plupload to make an ajax file uploading. Now the plupload.Uploader class has
I can make a DAO recordset in VB6/Access do anything - add data, clean
I can make Firefox not display the ugly dotted focus outlines on links with
How can make a link within a facebox window that redirects it to another
I can make a single row IKImageBrowserView by setting the [imageBrowser setContentResizingMask:NSViewWidthSizable]; but in

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.