kaziveh
kaziveh

Reputation: 57

Error with database file path in project with many databases

I have an error with database file path, the project has many databases with 10 tables, for each file should have 1 database, I create a database but it can't be saved as file ... and the error is:

The File Path Is Not Supported ...

public class filewrite
{
    public string datadress, dataname, databaseadress, tablexist, dsname, databak, dataldf, databakldf, filepath, filename;
    public filewrite()
    {
        databaseadress = "baseadress";
        dataname = "name";
        datadress = "adress";
        dsname = "databasename1";
        databak = "backUp";
        tablexist = "yesorno";
        dataldf = "dl";
         databakldf = "dbl";
        filepath = "path";
        filename = "name";
    }

    public byte writing()
    {
        if (File.Exists(filepath + @"\" + filename + @"\Data" + datadress))
            File.Delete(filepath + @"\" + filename + @"\Data" + datadress);
        if (File.Exists(@"C:\tempFile.SMP"))
            File.Delete(@"C:\tempFile.SMP");

        string path = filepath + @"\" + filename + @"\Data" + datadress;
        FileStream fpath = File.Create(path);(The error is in here)
        try
        {
            // read from file or write to file
            StreamWriter fwrite = new StreamWriter(fpath);
            fwrite.WriteLine(datadress);
            fwrite.WriteLine(dataname);
            fwrite.WriteLine(databaseadress);
            fwrite.WriteLine(tablexist);
            fwrite.WriteLine(dsname);
            fwrite.WriteLine(databak);
            fwrite.WriteLine(dataldf);
            fwrite.WriteLine(databakldf);
            fwrite.Close();   
        }
        finally
        {
        }
        File.Copy(filepath + @"\" + filename + @"\Data" + datadress, @"C:\tempFile.SMP");
        return 10;
    }
}

Upvotes: 2

Views: 169

Answers (1)

Vignesh Kumar A
Vignesh Kumar A

Reputation: 28403

Rather than using filepath + @"\" + filename + @"\Data" + datadress;,

Try using System.IO.Path.Combine instead:

Path.Combine(filepath, fileName, Data, datadress);

which returns a string.

Upvotes: 2

Related Questions