Home folder for project

  • Thread starter Thread starter bz
  • Start date Start date
B

bz

Hi,

I have a winforms project, and I use several files as content
resources (MS reports, RDL), located in a Reports subfolder.

At runtime I create the reports path by combining
Application.StartupFolder with Reports subfolder, but when running
from VS, the exe is in debug\bin or release\bin, and Reports is not a
subfolder of it. Right now I check the path and if it contaimns Debug
\bin or Release\bin, I remove it from path to calculate homepath, but
I'm not happy with this solution.

Is there any better, generic solution to access subfolders of project
home dir?

Thanks
 
Hi bz!
I have a winforms project, and I use several files as content
resources (MS reports, RDL), located in a Reports subfolder.

IMO, that's a design error. You shouldn't have any user files in your
application directory because that would require your user to have
sufficient rights. Instead, use the "Documents And Settings" folder or
simlar. You can get the path of these special folders using the function

System.Environment.GetFolderPath

For example, use System.Environment.SpecialFolder.LocalApplicationData
as the first parameter, to get the folder "%HOMEPATH%\Local
Settings\Application Data".

HTH,

Michael
 
Hi,
IMO, that's a design error. You shouldn't have any user files in your
application directory because that would require your user to have
sufficient rights. Instead, use the "Documents And Settings" folder or
simlar. You can get the path of these special folders using the function

System.Environment.GetFolderPath

For example, use System.Environment.SpecialFolder.LocalApplicationData
as the first parameter, to get the folder "%HOMEPATH%\Local
Settings\Application Data".

Those are report files (RDL/DRLC), which user should not modify. They
are deployed as part of the setup kit, set as Content files (so they
get installed into application's home folder)

Any suggestions?

Thanks
 
I have a winforms project, and I use several files as content
resources (MS reports, RDL), located in a Reports subfolder.

At runtime I create the reports path by combining
Application.StartupFolder with Reports subfolder, but when running
from VS, the exe is in debug\bin or release\bin, and Reports is not a
subfolder of it. Right now I check the path and if it contaimns Debug
\bin or Release\bin, I remove it from path to calculate homepath, but
I'm not happy with this solution.

Is there any better, generic solution to access subfolders of project
home dir?

Create an application setting called "ReportFolder." Check this setting at
startup and, if empty, do you string concatenation and save it. That way,
when the user executes the program for the first time, the correct path will
be generated and used from then on (providing he never moves the program
folder...).

While developing in the IDE, hardcode this value to your working report
folder, and then your program will work fine no matter what version
(debug/release) you're running.

The only gotcha is that you MUST remember to blank this value out before
creating your setup program (or publishing with ClickOnce, etc.), or the
user will get an invalid path.
 
Thanks for suggestion, but there isn't really as build-in option to
support such scenario out of the box?

Greetings
 
Thanks for suggestion, but there isn't really as build-in option to
support such scenario out of the box?

No, there isn't. The program has no way of knowing that it's being run via
the IDE and therefore it cannot adjust its behavior accordingly. It's just
one of the facts of development you have to live with.
 
Hi,
I have a winforms project, and I use several files as content
resources (MS reports, RDL), located in a Reports subfolder.

At runtime I create the reports path by combining
Application.StartupFolder with Reports subfolder, but when running
from VS, the exe is in debug\bin or release\bin, and Reports is not a
subfolder of it. Right now I check the path and if it contaimns Debug
\bin or Release\bin, I remove it from path to calculate homepath, but
I'm not happy with this solution.

Is there any better, generic solution to access subfolders of project
home dir?

Thanks


Settings [Project->Options->Build->Output Path] to the ".\" solves you
problem, if \Report folder in solution folder or the projects

Also you sould see ome cool reports like this one (See
[Tools->Options->Projects And Solutions->Build And Run], if you set
[MSBuild] to "Normal")

------ Build started: Project: MDIApplication, Configuration: Debug
x86 ------
Build started 17.03.2009 23:15:38.
Target CoreResGen:
Processing resource file "Form1.resx" into
"obj\x86\Debug\MDIApplication.Form1.resources".
Processing resource file "Form2.resx" into
"obj\x86\Debug\MDIApplication.Form2.resources".
Processing resource file "Properties\Resources.resx" into
"obj\x86\Debug\MDIApplication.Properties.Resources.resources".
Target CoreCompile:
C:\Windows\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig
/nowarn:1701,1702 /platform:x86 /errorreport:prompt /define:DEBUG;TRACE
/reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll
/reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Deployment.dll
/reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll
/reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll
/reference:"c:\Program Files (x86)\Microsoft Chart
Controls\Assemblies\System.Windows.Forms.DataVisualization.dll"
/reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll
/reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll
/debug+ /debug:full /filealign:512 /out:obj\x86\Debug\MDIApplication.exe
/resource:obj\x86\Debug\MDIApplication.Form1.resources
/resource:obj\x86\Debug\MDIApplication.Form2.resources
/resource:obj\x86\Debug\MDIApplication.Properties.Resources.resources
/target:winexe Form1.cs Form1.Designer.cs Form2.cs Form2.Designer.cs
Program.cs Properties\AssemblyInfo.cs Properties\Resources.Designer.cs
Properties\Settings.Designer.cs

Compile complete -- 0 errors, 0 warnings
Target CopyFilesToOutputDirectory:
Copying file from "obj\x86\Debug\MDIApplication.exe" to
".\MDIApplication.exe".
MDIApplication ->
C:\Projects\InPlaceHostingManager\MDIApplication\MDIApplication\MDIApplication.exe
Copying file from "obj\x86\Debug\MDIApplication.pdb" to
".\MDIApplication.pdb".
Target IncrementalClean:
Deleting file
"C:\Projects\InPlaceHostingManager\MDIApplication\MDIApplication\bin\x86\Debug\MDIApplication.exe".
Deleting file
"C:\Projects\InPlaceHostingManager\MDIApplication\MDIApplication\bin\x86\Debug\MDIApplication.pdb".

Build succeeded.

Time Elapsed 00:00:01.11
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
 
No, there isn't. The program has no way of knowing that it's being run via
the IDE and therefore it cannot adjust its behavior accordingly. It's just
one of the facts of development you have to live with.

There is. See:

Settings [Project->Options->Build->Output Path] to the ".\" solves
you
problem, if \Report folder in solution folder or the projects

Also you sould see ome cool reports like this one (See
[Tools->Options->Projects And Solutions->Build And Run], if you set
[MSBuild] to "Normal")

------ Build started: Project: MDIApplication, Configuration: Debug
x86 ------
Build started 17.03.2009 23:15:38.
Target CoreResGen:
....
Target CoreCompile:
....
Compile complete -- 0 errors, 0 warnings
Target CopyFilesToOutputDirectory:
Copying file from "obj\x86\Debug\MDIApplication.exe" to
".\MDIApplication.exe".
MDIApplication ->
C:\Projects\InPlaceHostingManager\MDIApplication\MDIApplication
\MDIApplication.exe
Copying file from "obj\x86\Debug\MDIApplication.pdb" to
".\MDIApplication.pdb".
Target IncrementalClean:
Deleting file
"C:\Projects\InPlaceHostingManager\MDIApplication\MDIApplication\bin
\x86\Debug\MDIApplication.exe".
Deleting file
"C:\Projects\InPlaceHostingManager\MDIApplication\MDIApplication\bin
\x86\Debug\MDIApplication.pdb".

Build succeeded.

Time Elapsed 00:00:01.11
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped
==========
 
Hi,

I have a winforms project, and I use several files as content
resources (MS reports, RDL), located in a Reports subfolder.

At runtime I create the reports path by combining
Application.StartupFolder with Reports subfolder, but when running
from VS, the exe is in debug\bin or release\bin, and Reports is not a
subfolder of it. Right now I check the path and if it contaimns Debug
\bin or Release\bin, I remove it from path to calculate homepath, but
I'm not happy with this solution.

Is there any better, generic solution to access subfolders of project
home dir?

Thanks

Settings [Project->Options->Build->Output Path] to the ".\" solves
you
problem, if \Report folder in solution folder or the projects

Also you sould see some verbose reports like this one (See
[Tools->Options->Projects And Solutions->Build And Run], if you set
[MSBuild] to "Normal")

------ Build started: Project: MDIApplication, Configuration: Debug
x86 ------
Build started 17.03.2009 23:15:38.
Target CoreResGen:
Processing resource...
Target CoreCompile:
C:\Windows\Microsoft.NET\Framework\v3.5\Csc.exe...
Compile complete -- 0 errors, 0 warnings
Target CopyFilesToOutputDirectory:
Copying file from "obj\x86\Debug\MDIApplication.exe" to
".\MDIApplication.exe".
MDIApplication ->
C:\Projects\InPlaceHostingManager\MDIApplication\MDIApplication
\MDIApplication.exe
Copying file from "obj\x86\Debug\MDIApplication.pdb" to
".\MDIApplication.pdb".
Target IncrementalClean:
Deleting file
"C:\Projects\InPlaceHostingManager\MDIApplication\MDIApplication\bin
\x86\Debug\MDIApplication.exe".
Deleting file
"C:\Projects\InPlaceHostingManager\MDIApplication\MDIApplication\bin
\x86\Debug\MDIApplication.pdb".

Build succeeded.

Time Elapsed 00:00:01.11
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped
==========
 
Back
Top