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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:15:23+00:00 2026-05-17T15:15:23+00:00

Can someone tell me what is going to happen in this code when an

  • 0

Can someone tell me what is going to happen in this code when an error is encountered? Ideally it should continue the foreach statement until it gets to the last record, but I suspect it’s stopping in the middle of the operation because when I check the number of files moved it’s off by 225. If it is in fact stopping because of an error, what can I do to make it continue the loop?

I’m creating a new upload manager for our software and need to clean the old files up. There are about 715 orphaned files equaling around 750 MB after a year and a half of use because the original developers didn’t write the code to correctly overwrite old files when a new one was uploaded. They also saved the files in a single directory. I can’t stand that so I’m moving all of the files into a structure – Vessel Name – ServiceRequesetID – files uploaded for that service. I’m also giving the users a gridview to view and delete files they no longer need as they work the service.

protected void Button1_Click(object sender, EventArgs e)
{

    GridViewRow[] rowArray = new GridViewRow[gv_Files.Rows.Count];
    gv_Files.Rows.CopyTo(rowArray, 0);

    int i = -1;

    foreach(GridViewRow row in rowArray)
    {
        i++;
        string _serviceRequestID = ((Label)gv_Files.Rows[row.RowIndex].FindControl("lbl_SRID")).Text;
        string _vesselName = ((Label)gv_Files.Rows[row.RowIndex].FindControl("lbl_VesselID")).Text;
        string _uploadDIR = Server.MapPath("uploadedFiles");
        string _vesselDIR = Server.MapPath("uploadedFiles" + "\\" + _vesselName);
        string _fileName = ((Label)gv_Files.Rows[row.RowIndex].FindControl("lbl_FileName")).Text;
        DirectoryInfo dInfo = new DirectoryInfo(_uploadDIR);
        DirectoryInfo dVessel = new DirectoryInfo(_vesselDIR);
        DirectoryInfo dSRID = new DirectoryInfo(_serviceRequestID);
        dInfo.CreateSubdirectory(_vesselName);
        dVessel.CreateSubdirectory(_serviceRequestID);

        string _originalFile = _uploadDIR + "\\" + _fileName;
        string _fileFullPath = Path.Combine(Server.MapPath("uploadedFiles/" + _vesselName + "/" + _serviceRequestID + "/"), _fileName);
        FileInfo NewFile = new FileInfo(_fileFullPath);
        string _fileUploadPath = _vesselName + "/" + _serviceRequestID + "/" + _fileName;
        string sourceFile = _originalFile;
        FileInfo _source = new FileInfo(sourceFile);
        string destinationFile = _fileFullPath;

            try
            {
                {
                    File.Move(sourceFile, destinationFile);
                    movefiles.InsertNewUploadPath(Convert.ToDecimal(_serviceRequestID), 1, _fileUploadPath);
                }
            }
            catch (Exception ex)
            {
                CreateLogFiles Err = new CreateLogFiles();
                Err.ErrorLog(Server.MapPath("Logs/ErrorLog"), ex.Message);

            }
    }

    _utility.MessageBox("Completed processing files.");
}
  • 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-17T15:15:24+00:00Added an answer on May 17, 2026 at 3:15 pm

    As long as the error encountered occurs within the try catch clause, the code will continue executing within the foreach loop. However, if the error occurs outside of the try catch, the function will exit and throw an error. How many files does your error log report??

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

Sidebar

Related Questions

Can someone tell me whats going wrong in this code! testit :- read(Term1), read(Term2),
Can someone tell me what's going on with this bit of code using boost's
Can someone tell me why this http://hupcapstudios.com/projects/calendar.html won't load in IE? The error message:
Can someone tell me where I am going wrong with this class. It is
Please, can someone tell me what does this.init.apply(this, arguments) do in the code below?
Can someone tell me what is going on with the code below: 'Variables at
Just a quick question, can someone tell me where this is going wrong, I'm
I seem to be going wrong somewhere in this INSERT query. Can someone tell
Can someone tell me how to modify this regex to allow periods in a
can someone tell me what seems to be the issue with this <?php $increment

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.