0

I am developing a windows phone 8 app using sqlite and am trying to check if the database exists and if it doesnt exist,it should be created. but i keep getting the error message "System.windows.shapes.path does not contain a definition for combine". Is there another way to do it or how can i improve it?

public static string DB_PATH = Path.Combine(Path.Combine(ApplicationData.Current.LocalFolder.Path, "ContactsManager.sqlite"));//DataBase Name 
    public App()
    {
        if (!CheckFileExists("ContactsManager.sqlite").Result)
        {
            using (var db = new SQLiteConnection(DB_PATH))
            {
                db.CreateTable<Contacts>();
            }
        }
    }

    private async Task<bool> CheckFileExists(string fileName)
    {
        try
        {
            var store = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync(fileName);
            return true;
        }
        catch
        {
        }
        return false;
    }
1
  • 1
    Path.Combine is defined in System.IO.Path. Commented Sep 11, 2015 at 13:37

4 Answers 4

2

Do you really need to check if the database exist? I don't know about windows phone, but in Windows, as soon as you try to add a table into a SQLite database, if the database doesn't exist, it creates it. If you are worried about the table existing already, you can use:

CREATE TABLE IF NOT EXISTS tableName(...)

(I tried to ask it as comment but I don't have the reputation)

Sign up to request clarification or add additional context in comments.

Comments

1

Why do you have a Path.Combine in a Path.Combine? If Path.Combine is not available with one or two parameter, why not simple concat two strings?

You have it 2x: public static string DB_PATH = Path.Combine(Path.Combine(ApplicationData.Current.LocalFolder.Path, "ContactsManager.sqlite"));

6 Comments

Path.Combine does accept two parameters. It's either a typo or copy pasted code on the OP's part
It also could be his problem, because the compiler say: System.windows.shapes.path does not contain a definition for combine or am i wrong?
maybe i am blind but the method with one string parameter (msdn.microsoft.com/de-de/library/dd991142(v=vs.110).aspx) is available since windows phone 8.1
Wrong. Path.Combine is in the System.IO.Path class. You probably added the wrong reference
Yep totally wrong. my fault. i will delete the answer
|
1

you can check by this:

public async Task<bool> isFilePresent(string fileName)
 {
 return System.IO.File.Exists(string.Format(@"{0}\{1}", ApplicationData.Current.LocalFolder.Path, fileName);
 }

Comments

0

@Panagiotis Kanavos's comment was right, you have resolved the Path class using wrong namespace!

Remove

using System.Windows.Shapes; // for silverlite
using Windows.UI.Xaml.Shapes; // for winrt

and add

using System.IO;

1 Comment

thank you...it worked perfect.. i removed using System.windows.shapes and replaced it with using System.IO

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.