0

I managed to create a database using Linq-to-SQL with the following code:

private static DataClasses1DataContext _dataDC = new DataClasses1DataContext(@"C:\\database1.mdf");

public AddClient()
{
    InitializeComponent();
    DataContext = this;
       _dataDC.CreateDatabase();
}

and this created a new local database on C: .

How can I change the @"C:\\database1.mdf" so that the file is created in the current directory from where I run the program ?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Sas Gabriel
  • 1,544
  • 2
  • 20
  • 27

2 Answers2

0

You can use one of these that suits your application and pass it in to new DataClasses1DataContext(HERE);

System.IO.Directory.GetCurrentDirectory();

Environment.CurrentDirectory;

Request.PhysicalPath
HatSoft
  • 11,077
  • 3
  • 28
  • 43
0

Check here how to ge the current directory path. Incude it inside parentheses:

How can I get the application's path in a .NET console application?

Community
  • 1
  • 1
Mitja Bonca
  • 4,268
  • 5
  • 24
  • 30