Say you have an existing linked table named [Foo] that points to the following CSV file:
C:\Users\Gord\Desktop\foo.csv
Access stores the linking information in a TableDef object named "Foo" with the following properties:
.Name = "Foo"
.Connect = "Text;DSN=Foo Link Specification;FMT=Delimited;HDR=NO;IMEX=2;CharacterSet=437;ACCDB=YES;DATABASE=C:\Users\Gord\Desktop"
.SourceTableName = "foo.csv"
Notice that the DATABASE= parameter of the .Connect property indicates the folder in which the CSV file resides, and the .SourceTableName property indicates the name of the CSV file.
If you move that file from C:\Users\Gord\Desktop to C:\Users\Public then all you need to do is update the DATABASE= parameter of the .Connect property with the new location:
// required COM reference: Microsoft Office 14.0 Access Database Engine Object Library
//
// using Microsoft.Office.Interop.Access.Dao; ...
var dbe = new DBEngine();
Database db = dbe.OpenDatabase(@"C:\Users\Public\Database1.accdb");
TableDef tbd = db.TableDefs["Foo"];
string oldConnect = tbd.Connect;
char[] delimiter = { ';' };
string[] connectParams = oldConnect.Split(delimiter);
for (int i = 0; i < connectParams.Length; i++)
{
if (connectParams[i].StartsWith("DATABASE=", StringComparison.InvariantCultureIgnoreCase))
{
connectParams[i] = @"DATABASE=C:\Users\Public";
break;
}
}
string newConnect = String.Join(Convert.ToString(delimiter[0]), connectParams);
tbd.Connect = newConnect;
tbd.RefreshLink();
db.Close()