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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:42:41+00:00 2026-06-03T00:42:41+00:00

I had a FileUpload control earlier to upload each file individually in the database.

  • 0

I had a FileUpload control earlier to upload each file individually in the database. But now I want to be able to do bulk upload.

My requirement is that a csv file contains the filename and filepath, I need to upload the csv using FileUpload and eventually run a code that reads the csv and inserts each file into a table ApplicantAttachment. ApplicantAttachment has columns fileName (NVARCHAR), FilePath(NVARCHAR), Attachment (VARBINARY). In this attachment column, I need to save the binary format of the files mentioned in the csv.
MY CSV looks like this
FileName FilePath
dl-54a.pdf c:\users\abc\desktop\dl-54a.pdf
xyz.doc c:\users\abc\desktop\xyz.doc

I wish I could do something like this. But I know we caanot assing filename etc to the Fileupload object. Any suggestions would be helpful.

    <asp:FileUpload ID="csvFile" runat="server" Width="400" /></td>
    <asp:Button ID="btnUpload" Text="Upload" runat="server" OnClick="btnUpload_Click" /></td>
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        if (csvFile.HasFile)
        {
            List<string[]> filesToUpload = parseCSV(csvFile.PostedFile.FileName);
            SaveFiles(filesToUpload);
        }
    }

    public List<string[]> parseCSV(string path)
    {
        List<string[]> parsedData = new List<string[]>();
        try
        {
            using (StreamReader readFile = new StreamReader(path))
            {
                string line;
                string[] row;

                while ((line = readFile.ReadLine()) != null)
                {
                    if (!readFile.ReadLine().Contains("ApplicantId"))
                    {
                        row = line.Split(',');                            
                        parsedData.Add(row);
                    }
                }
            }
        }
        catch (Exception e)
        {
            ;
        }

        return parsedData;
    }

    private void SaveFiles(List<string[]> files)
    {
        foreach (string[] attachment in files)
        {
            using (DataClasses1DataContext db = new DataClasses1DataContext())
            {
                FileUpload fu = new FileUpload();
                fu.FileName = attachment[1].ToString();
                if (fu.HasFile)
                {
                    ApplicantAttachment aa1 = new ApplicantAttachment();
                    aa1.Filename = attachment[0].ToString();
                    aa1.FileType = fu.PostedFile.ContentType;
                    aa1.Attachment = fu.FileBytes;
                    db.ApplicantAttachments.InsertOnSubmit(aa1);
                    db.SubmitChanges();
                }
            }
        }
    }
  • 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-06-03T00:42:42+00:00Added an answer on June 3, 2026 at 12:42 am

    This is what works. FileUpload cant be used.

         private void SaveFiles(List<string[]> files)
         {
            foreach (string[] attachment in files)
            {
                using (DataClasses1DataContext db = new DataClasses1DataContext())
                {
                    string path = attachment[1].ToString();
                    byte[] fileBytes = File.ReadAllBytes(path);
    
                    ApplicantAttachment aa1 = new ApplicantAttachment();
                    aa1.Filename = attachment[0].ToString();
                    aa1.FileType = MIMEType.GetType(attachment[1].ToString());
                    aa1.Attachment = fileBytes;
                    db.ApplicantAttachments.InsertOnSubmit(aa1);
                    db.SubmitChanges();
    
                }
            }
         }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, I'm unable to upload a file with the <asp:FileUpload /> control.
i had used this plugin before, but now when i want to use it
I had a file upload that was uploading to a folder in the web
From my php script, i need to be able to upload a csv file
im trying to use a file upload control from the obout control library, i
I have a HTML form ( upload.htm ) with a HTML file upload control
I'm writing a WCF Service to Upload file using REST. But my probleme come
Many might have had experience using File Upload widget from Yahoo User Interface library
Had a few problems getting background-image displaying in Firefox, I made it work but
Had a good search here but can't see anything that gets my mind 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.