How would I be able to use a file in visual studio project on any computer?

54 views Asked by At

I have a project that let's say loads a excel file to a string using this connection:

string PATH = @"C:\localfile\user\bob\firstcomputer\file.xlsx";
        string connection = "Provider=Microsoft.ACE.OLEDB.12.0;
                             Data Source=" + PATH + ";Extended Properties=Excel 12.0";
......... ..... ...blah blah blah loads excel to string ect.

I want to use this visual project on another computer without having to change the string path to match that computer's. Is there a way to reference that file so that using it on any computer will work without changing the path in the first place?

2

There are 2 answers

0
ojblass On

You would write a program that would ask for a location of a file before launching the application. The only computer specific data I see in your code is the location of the file. You might also add error checking to determine if it could find excel and the related OLEDB provider.

2
devKev On

One solution would be to store the file in a shared location (shared drive, for instance) that multiple computers are mapped to - this way, you wouldn't have to worry about changing the file path or mimicking the file structure on each computer.