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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:25:33+00:00 2026-05-12T16:25:33+00:00

I have a bulk uploading object in place that is being used to bulk

  • 0

I have a bulk uploading object in place that is being used to bulk upload roughly 25-40 image files at a time. Each image is about 100-150 kb in size.

During the upload, I’ve created a for each loop that takes the file name of the image (minus the file extension) to write it into a column named “sku”. Also, for each file being uploaded, the date is recorded to a column named DateUpdated, as well as some image path data.

Here is my c# code:

protected void graphicMultiFileButton_Click(object sender, EventArgs e)
 {

 //graphicMultiFile is the ID of the bulk uploading object ( provided by Dean Brettle: http://www.brettle.com/neatupload  )

   if (graphicMultiFile.Files.Length > 0)

          {
           foreach (UploadedFile file in graphicMultiFile.Files)
             {
                 //strip ".jpg" from file name (will be assigned as SKU)
                  string sku = file.FileName.Substring(0, file.FileName.Length - 4);

                 //assign the directory where the images will be stored on the server
                 string directoryPath = Server.MapPath("~/images/graphicsLib/" + file.FileName);

                 //ensure that if image existes on server that it will get overwritten next time it's uploaded:
                 file.MoveTo(directoryPath, MoveToOptions.Overwrite);

                 //current sql that inserts a record to the db
                SqlCommand comm;
                SqlConnection conn;
                string connectionString = ConfigurationManager.ConnectionStrings["DataConnect"].ConnectionString;
                conn = new SqlConnection(connectionString);
                 comm = new SqlCommand("INSERT INTO GraphicsLibrary (sku, imagePath, DateUpdated) VALUES (@sku, @imagePath, @DateUpdated)", conn);

                comm.Parameters.Add("@sku", System.Data.SqlDbType.VarChar, 50);
                comm.Parameters["@sku"].Value = sku;

               comm.Parameters.Add("@imagePath", System.Data.SqlDbType.VarChar, 300);
               comm.Parameters["@imagePath"].Value = "images/graphicsLib/" + file.FileName;

               comm.Parameters.Add("@DateUpdated", System.Data.SqlDbType.DateTime);
              comm.Parameters["@DateUpdated"].Value = DateTime.Now;

             conn.Open();
             comm.ExecuteNonQuery();
             conn.Close();


           }
         }
      }

After images are uploaded, managers will go back and re-upload images that have previously been uploaded.

This is because these product images are always being revised and improved.

For each new/improved image, the file name and extension will remain the same – so that when image 321-54321.jpg was first uploaded to the server, the new/improved version of that image will still have the image file name as 321-54321.jpg.

I can’t say for sure if the file sizes will remain in the 100-150KB range. I’ll assume that the image file size will grow eventually.

When images get uploaded (again), there of course will be an existing record in the database for that image.
What is the best way to:

  1. Check the database for the existing record (stored procedure or SqlDataReader or create a DataSet …?)
  2. Then if record exists, simply UPDATE that record so that the DateUpdated column gets today’s date.
  3. If no record exists, do the INSERT of the record as normal.

Things to consider:

If the record exists, we’ll let the actual image be uploaded. It will simply overwrite the existing image so that the new version gets displayed on the web.

We’re using SQL Server 2000 on hosted environment (DiscountAsp).

I’m programming in C#.

The uploading process will be used by about 2 managers a few times a month (each) – which to me is not a allot of usage.

Although I’m a jr. developer, I’m guessing that a stored procedure would be the way to go. Just seems more efficient – to do this record check away from the for each loop… but not sure. I’d need extra help writing a sproc, since I don’t have too much experience with them.

Thank everyone…

  • 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-12T16:25:33+00:00Added an answer on May 12, 2026 at 4:25 pm

    The loop will be faster in managed code (rather than in the stored procedure). I would use the following code with the following stored procedure:

    if (graphicMultiFile.Files.Length > 0)          
            {       
                string connectionString = ConfigurationManager.ConnectionStrings["DataConnect"].ConnectionString;                
                foreach (UploadedFile file in graphicMultiFile.Files)             
                {                 
                    string sku = file.FileName.Substring(0, file.FileName.Length - 4);                 
                    string directoryPath = Server.MapPath("~/images/graphicsLib/" + file.FileName);                 
                    file.MoveTo(directoryPath, MoveToOptions.Overwrite);                 
    
                    SqlConnection conn = new SqlConnection(connectionString);       
                    SqlCommand comm = new SqlCommand("exec addOrUpdateImageRecord @sku, @imagePath");                
                    comm.Parameters.Add("@sku", System.Data.SqlDbType.VarChar, 50);                
                    comm.Parameters["@sku"].Value = sku;               
                    comm.Parameters.Add("@imagePath", System.Data.SqlDbType.VarChar, 300);               
                    comm.Parameters["@imagePath"].Value = "images/graphicsLib/" + file.FileName;               
                    conn.Open();             
                    comm.ExecuteNonQuery();             
                    conn.Close();           
                }         
            }      
    

    Here’s the code for the stored procedure:

    CREATE PROCEDURE dbo.addOrUpdateImageRecord(
            @sku varchar(50),
            @imagePath varchar(300))
    
    AS
    
        DECLARE @ExistenceCheck int
        SELECT @ExistenceCheck = COUNT(*)
        FROM GraphicsLibrary 
        WHERE sku=@sku 
    
        IF(@ExistenceCheck=0)
        BEGIN 
            INSERT INTO GraphicsLibrary (sku, imagePath, DateCreated) 
            VALUES(@sku, @imagePath, GETDATE()) 
        END
        ELSE
        BEGIN
            UPDATE GraphicsLibrary 
            SET DateUpdated = GETDATE() 
            WHERE sku = @sku
        END
    
    
    GO
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have bulk of images (1000+); each image consists of several pictures as a
I have a client who wants to bulk-upload photo files to her existing Ruby
I have a question regarding bulk uploading with icefaces. Currently I can upload one
I have a bulk insert command that I am issuing through C#. Is the
I have in outer form_tag so that I can have bulk actions. but then
I have some bulk images inside DIV tag and If I click an image
I have built a bulk email sending website for a client that is required
I have to perform a bulk operation bool AddEntitiesX(List<X>) : For each insert of
I have a list of key names that I want to bulk fetch (the
I have found a suitable way to let user bulk upload images http://www.plupload.com/index.php After

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.