Problem to save Excel file

Hi,
Using these
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Text.RegularExpressions;
using System.Globalization;
using System.Collections;
using System.Diagnostics;
using System.Drawing;
using Microsoft.Office.Interop;
using Excel = Microsoft.Office.Interop.Excel;
...
            Excel.Application xlApp = new
            Microsoft.Office.Interop.Excel.Application();
            workbook = xlApp.Workbooks.Add(misValue);

            workbook = xlApp.Workbooks.Add(misValue);
            worksheet = (Excel.Worksheet)workbook.Worksheets.get_Item(1);

            ...
            workbook.SaveAs("c://" + hkb + ".xls", Excel.XlFileFormat.xlExcel8, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
            workbook.Close(true, misValue, misValue);
            xlApp.Quit();

Open in new window


on VS 2013, I get this error
https://dl.dropboxusercontent.com/u/40211031/tt119.png

when running the project. why?
LVL 12
HuaMin ChenProblem resolverAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Haris DulicIT ArchitectCommented:
Hi,

it seams the issue is with file name can you try:

dim file_name as string

file_name= "c://" + hkb + ".xls"

 MessageBox.Show (file_name, "Test",MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);

workbook.SaveAs(file_name, Excel.XlFileFormat.xlExcel8, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);

Open in new window

0
HuaMin ChenProblem resolverAuthor Commented:
Yes, using these codes

                fl_nm = "c://" + hkb + ".xls";
                workbook.SaveAs(fl_nm, Excel.XlFileFormat.xlExcel8, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
                workbook.Close(true, misValue, misValue);
                xlApp.Quit();

Open in new window

I still get this exception

Error encountered when saving Excel file 'c://HKB.xls'   at Microsoft.Office.Int
erop.Excel._Workbook.SaveAs(Object Filename, Object FileFormat, Object Password,
 Object WriteResPassword, Object ReadOnlyRecommended, Object CreateBackup, XlSav
eAsAccessMode AccessMode, Object ConflictResolution, Object AddToMru, Object Tex
tCodepage, Object TextVisualLayout, Object Local)
   at FX_Pos_rep.Program.Main(String[] args)

Open in new window

0
AndyAinscowFreelance programmer / ConsultantCommented:
Probably a user permissions problem - saving to the root directory C, try creating a sub folder and saving to that instead.
0
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

HuaMin ChenProblem resolverAuthor Commented:
It is saving to root directory now. And I have no such problem to save to root dir, using other application.
0
Haris DulicIT ArchitectCommented:
Hi,

check the rights on folders "C:\Windows\SysWOW64\config\systemprofile" and/or   "C:\Windows\System32\config\systemprofile" and set it to Full control as described here
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HuaMin ChenProblem resolverAuthor Commented:
Sorry, I have a problem to set

C:\Windows\SysWOW64\config\systemprofile

to Full control.
0
AndyAinscowFreelance programmer / ConsultantCommented:
>>And I have no such problem to save to root dir, using other application.

OK, so you don't want to test something simple.  (Look, if it is not this problem it takes you a minute to confirm that - if it is this problem you waste hours).
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Legacy OS

From novice to tech pro — start learning today.