Solved

Need help with MS VS 2010 Deployment Project

Posted on 2014-07-19
2
171 Views
Last Modified: 2014-07-20
I have a WinForms application created using MS VS 2010.  I created a deployment package but am having a problem accessing a folder in the package.

I have a function to export data.  I want the exported data to be stored in a folder in the user's My Documents folder.  In my deployment package I have added User's Personal Data Folder to the File System in the Deployment package.

MS Deployment

In my application I do the following to create the file.  I want the file to be created in the User's Personal Data folder.
            string mydocpath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            string FileName = mydocpath + @"\HWLocal77\Exports\Export_" + curDate.Month.ToString() + curDate.Year.ToString() + ".txt";
            using (StreamWriter sw = new StreamWriter(FileName))
            {
                // my extract code is here
            }

Open in new window


When I run the install, the HWLocal77\Exports is created in my My Documents folder but when I run the application and try and export the data, the application creates the following path:

C:\Users\Owner\Documents\HWLocal77\Exports\Export_72014.txt

and I get an error stating part of the path does not exist.  The folder exists in the My Documents folder.

My Documents
But it doesn't exist in the C:\Users\Owner\Documents folder.

Can someone please help me figure out how to change my Deployment Package or what change I need to make to my program?  Any help is greatly appreciated.
0
Comment
Question by:dyarosh
2 Comments
 
LVL 35

Accepted Solution

by:
Miguel Oz earned 500 total points
ID: 40207334
Your deployment package is OK, but your C# code is not because it does not create file if it does not exist, please replace:
using (StreamWriter sw = new StreamWriter(FileName))

Open in new window

with this constructor:
using (StreamWriter sw = new StreamWriter(FileName, false))

Open in new window

The extra parameter creates the file if it does not exist as per MSDN explanation: "Use false to overwrite the file. If the specified file does not exist, this parameter has no effect, and the constructor creates a new file. "
0
 

Author Closing Comment

by:dyarosh
ID: 40207476
After looking closer at the error message I realized the folder name was being created as "HWLocal77" but the folder was "HWLocal 77".  Once I fixed that everything worked.  Thank you for your help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now