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

  • Home
  • SEARCH
  • 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 8618447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:06:45+00:00 2026-06-12T06:06:45+00:00

public void CreateFileOutput(object parameter) { string workSheetName, targetFile; workSheetName = data; targetFile = data.csv;

  • 0
        public void CreateFileOutput(object parameter)
        {
            string workSheetName, targetFile;
            workSheetName = "data"; targetFile = "data.csv";
            string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + SourceAppFilePath + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1;';";
            OleDbConnection conn = null;
            StreamWriter wrtr = null;
            OleDbCommand cmd = null;
            OleDbDataAdapter da = null;
            try
            {
                conn = new OleDbConnection(strConn);
                conn.Open();
                cmd = new OleDbCommand("SELECT * FROM [" + workSheetName + "$]", conn);
                cmd.CommandType = CommandType.Text;
                wrtr = new StreamWriter(targetFile);
                da = new OleDbDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);
                for (int x = 0; x < dt.Rows.Count; x++)
                {
                    string rowString = "";
                    for (int y = 0; y < dt.Columns.Count; y++)
                    {
                        rowString += "\"" + dt.Rows[x][y].ToString() + "\",";
                    }
                    wrtr.WriteLine(rowString);
                }
                Console.WriteLine();
                Console.WriteLine("Done! Your " + SourceAppFilePath + " has been converted into " + targetFile + ".");
                Console.WriteLine();
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.ToString());
                Console.ReadLine();
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                    conn.Close();
                conn.Dispose();
                cmd.Dispose();
                da.Dispose();
                wrtr.Close();
                wrtr.Dispose();
            }
        }

XLS file is being converted to csv.I am able to see that in the for loop wrtr.WriteLine(rowString);
But I want to see the final output file “Data.csv” in the desktop location as I am taking the source .xls file from the desktop. Provide me a solution. Thanks.

  • 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-12T06:06:47+00:00Added an answer on June 12, 2026 at 6:06 am

    You need to use the full path to save the file to the desktop. You can get the path using the Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory, like this:

    string targetFolder =  Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
    string targetPath = Path.Combine(targetFolder, "Data.csv");
    

    Then use FileStream with the full path:

    fs = new FileStream(targetPath, FileMode.Create);
    

    Edited Per Comments Below

    The key to this is specifying the path to where you want to save the file. Just giving a file name will put it in the directory the application is excuting from. An easy way to do this would be to use the GetDirectoryName method of the Path class. Assuming the file was passed in, read from a config file, hard coded, etc:

    string path = Path.GetDirectoryName(sourceFile);
    string target = path + @”\” + “Data.csv”;

    If the sourceFile was C:\Data\Input.xml, then path would equal “C:\Data”, and target would be C:\Data\Data.csv.

    The advantage here is that you can pass a filename with the path, and it will always place the targetfile in the same location. This lends itself nicely to parameterization of the method, or maybe even having the user select the file through an OpenFileDialog box or similar mechanism.

    Additional Edit Per John’s Comment

    Based on the code you posted, the Data.xsl file is in the executing application’s folder. In that case, you’d simply need to do the following:

    fs = new FileStream("data.csv", FileMode.Create);
    

    No need to mess with paths, as the filestream will also go to the executing application’s directory.

    In the end, it’s all about using the information available from the sourcefile (i.e., it’s location/path data) and applying it to the target file’s full path and name.

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

Sidebar

Related Questions

public void CreateFileOutput(object parameter) { TransactFileCreation(); WPFMessageBox.Show(test, Process completed successfully.); } public void TransactFileCreation()
public void Submit1_Click(Object sender, EventArgs E) { string strheadlinesid1 = string.Empty; if (!IsPostBack) {
public void button2_Click(object sender, System.EventArgs e) { string text = textBox1.Text; Mainform = this;
public void Button1_Click(object sender, EventArgs e) { String a = DropDownList1.SelectedItem.Value; String b =
public void Foo (IEnumerable<object> objects) { } var strings = new List<string>{first, second, third};
public void GrabData() throws IOException { try { BufferedReader br = new BufferedReader(new FileReader(data/500.txt));
public void EditAndSave(String fileName) { Bitmap b = new Bitmap(fileName); /** * Edit bitmap
public void test(Object obj){ //Here i have to set the values of the obj
public void insertOrUpdate(String customerNumber, Long creditLimitAmount) throws SQLException { Connection connection2 = UBOCMSSQLConnectionUtill.getMSSqlConnection(); connection2.setAutoCommit(false);
public void Find() { String Value = ; System.out.println(Search Name); Value = Input.next(); int

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.