Avatar of Peter Kiers
Peter KiersFlag for Netherlands

asked on 

What's the best way to store your files?

Hi,

I have an application that uses a access-database. The database resides in the folder of the application.
And I use this code to access the database:


        private void mainForm_Load(object sender, EventArgs e)
        {
            AppPath = GetAppPath();
            DBConStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + AppPath + @"\DBRoot.mdb";
        }

        public static string GetAppPath()
        {
            string AppPath = "";
            try
            {
                AppPath = Path.GetFullPath(".");
                AppPath = AppPath.Replace(@"\bin\Debug", "");
                AppPath = AppPath.Replace(@"\bin\Release", "");
                if (AppPath.EndsWith(@"\") == false) { AppPath += @"\"; }
            }
            catch (Exception) { throw; }
            return AppPath;
        }

But when i install the application and run it, the data isn't loaded in my application.
But if I run it again but now with the command run as administrator it works.

What can i do about this?
What is the best way to store you files? Because the /bin/debug
folder is gone after the setup.

Who knows the answer and is willing to help me?

Peter
.NET ProgrammingC#

Avatar of undefined
Last Comment
starlite551
Avatar of bedanand
bedanand
Flag of Nepal image

You must set the read/write permission to the EveryOne or Users Group on the database file.
Configure the installer so that there is read/write permission to mdf file.
ASKER CERTIFIED SOLUTION
Avatar of bedanand
bedanand
Flag of Nepal image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of starlite551
starlite551
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of starlite551
starlite551
Flag of India image

using above snippet in the code everywhere will ensure that the file content is picked up from the currently located path of the executable.
Avatar of starlite551
starlite551
Flag of India image

Or Alternatively you can use this code too :
public static string GetAppPath()
{
     return System.Windows.Forms.Application.StartupPath;
}

Open in new window

Avatar of starlite551
starlite551
Flag of India image

Although \bin\debug folder vanishes after the setup the application won`t go into exception if you use the above snippets for paths.
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo