0

I am uploading a file to \temp\ but I want to access it through a hyperlink in a given column inside Access. I can successfully paste the string to the hyperlink field, but there´s no link between the string and the file itself.

I tried to copy paste a website address from a browser to Access, surprisingly the hyperlink is pasted along with the "string"

//upload arquivo
string conexaoAccess2 = ConfigurationManager.ConnectionStrings["conexaoAccess"].ToString();
using (OleDbConnection conexaodb1 = new OleDbConnection(conexaoAccess2))
{
    conexaodb1.Open();

    Random r = new Random();
    int n = r.Next();
    // pega somente nome 
    string[] f = camArq.Split('\\');
    string fn = f[(f.Length) - 1];
    string fullDest = @"C:\temp\" + nomeArqnoExt + n + fileExtension0;
    string q = "UPDATE tbl_reg SET Campo1 = @campo WHERE nome_user = @nome1";

    //copia arquivo para a pasta destino
    File.Copy(camArq, fullDest, true);

    //to save to the database
    OleDbCommand cmd = new OleDbCommand(q, conexaodb1);
    var parCamp = cmd.CreateParameter();
    parCamp.ParameterName = "campo";
    parCamp.DbType = DbType.String;
    parCamp.Value = fullDest;
    cmd.Parameters.Add(parCamp);

    var parNome1 = cmd.CreateParameter();
    parNome1.ParameterName = "nome1";
    parNome1.DbType = DbType.String;
    parNome1.Value = mdl.nome;
    cmd.Parameters.Add(parNome1);

    cmd.ExecuteNonQuery();
}

I expect the string to be copied as an hyperlink, nevertheless, there´s no DbType that assumes this type of data, is there? The actual results are: I can successfully paste the file path to the field, but the field contains no hyperlink to anything whatsoever:

Erik A
  • 31,639
  • 12
  • 42
  • 67
tkruise
  • 3
  • 7

1 Answers1

1

Access Hyperlink type field requires value that is composed of 3 parts separated by # character: displaytext#path#subreference. Options:

  1. If using Hyperlink type field in Access table design, include # characters in string to save.

  2. Just use a text field to save path string without # characters then use FollowHyperlink method in code or format string to hyperlink structure with concatenation expression: "#" & [fieldname] & "#" - calculate in query or textbox ControlSource and set textbox IsHyperlink property to yes.

June7
  • 19,874
  • 8
  • 24
  • 34