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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:17:09+00:00 2026-05-25T22:17:09+00:00

I’m trying to create a csv file from an excel file using MS Excel

  • 0

I’m trying to create a csv file from an excel file using MS Excel Interop in my C#/Winforms app.

Am getting this error on SaveAs method in the code below.

‘The file could not be accessed. Try one of the following:

• Make sure the specified folder exists. • Make sure the folder that
contains the file is not read-only. • Make sure the file name does
not contain any of the following characters: < > ? [ ] : | or
* • Make sure the file/path name doesn’t contain more than 218
characters.’z

I tried setting readonly to false in Workbook’s Open(…) method as per:
Problem saving excel file after inserting data , but still getting the same error.

In my code, the csv file path was:C:\
If I change the csv file path to C:\SomeFolder or some shared UNC path, then I dont get this error.

Please advise.COuld there be some permissions issues with C drive?

Heres the code:

xlApp = new Microsoft.Office.Interop.Excel.Application(); 
xlApp.DisplayAlerts = false;
xlApp.Visible = false; 
wbkSrc = xlApp.Workbooks.Open(m_sSrcFil, 
                        Type.Missing, false, Type.Missing, Type.Missing, 
                        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
                        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
                        Type.Missing, Type.Missing);


                wstSrc = (Worksheet)wbkSrc.Worksheets[sSrcSht]; 
                //wstSrc.Activate();

                rngWork = wstSrc.Cells.get_Range("H:H", System.Reflection.Missing.Value); 
                rngWork.NumberFormat = "General";

                dteTmpDate = Convert.ToDateTime(m_sBusDate); 
                sTmpFileName = m_sSrcFil.Substring(0, m_sSrcFil.IndexOf(".")) + "_" + 
                    m_sUserName + "_" + dteTmpDate.ToString("yyyy_MM_dd") + ".Csv";

                wstSrc.SaveAs(sTmpFileName, XlFileFormat.xlCSV, Type.Missing, 
                    Type.Missing, true, Type.Missing, Type.Missing, Type.Missing, 
                    Type.Missing, Type.Missing);
  • 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-25T22:17:10+00:00Added an answer on May 25, 2026 at 10:17 pm

    Clearly sTmpFileName is an invalid path. The error message tells you that. Perhaps m_sUserName contains characters that are not allowed. Perhaps it is a DOMAIN\USER format user name. Perhaps the file name really is too long. Or perhaps something else is up. Take a look at the actual value of sTmpFileName and you will have your explanation.


    As an aside, your code is mistaken in using SubString and IndexOf(".") to get the filename without the extension. Filenames can have multiple periods in them. The extension is simply that text after the final period. Consider these file names and how your code will deal with them:

    C:\My.Folder.Name\TheFile.xls
    C:\MyFolder\TheFile.Name.xls
    

    Instead you should use Path.GetFileNameWithoutExtension.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to create an if statement in PHP that prevents a single post
I am using Paperclip to handle profile photo uploads in my app. They upload
I am trying to understand how to use SyndicationItem to display feed which is

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.