Monday 15 July 2013

c# - Retrieving images using a file path stored in a sql database (nearly there!) -


OK, I think I'm close to making a break on it.

I have the following code, theoretically, to populate the image using a file path through a SQL database

  Public Zero Image1_Load (Object Sender, EventArgs e) {//// TLMMemberLogo code to retrieve image image - currently does not work !!! Var connectionstring = Configuration Manager Select the connection ["PDCConnectionString"]. ConnectionString; (Var cnd = cn.CreateCommand ()) (cn.Open ()) (var cn = new SqlConnection ("Data Source = STRSQL04; Initial Catalog = PDC; Integrated Security = True" Cmd.CommandText = "SELECT TblMemberlogo from LogoFilePath where member ID = '123' "; //cmd.Parameters.Add (" 1212 "," 5 "); {if reader.Read (using reader = cmd.ExecuteReader ()) }) {Var filepath = reader.GetString (0); Image1.ImageUrl = filepath; Label2.Text = filepath; now} I know that I'm close because the label returns the file path suitable for 2 member 123. However , Image1 still dangerous red cross The image code of this image control is only the following.  
  image id = "image 1" run = "server" height = "71px" width = "400px" onload = "Image1_Load" / Code>  

Anyone who helps me finish a great pint as I am on the verge of breaking (second)!

Please get the output out below HTML.

img id = "Image1" src = "file: c: \ online% 20 Reporting \ SQL% 20 Solutions \ Member% 20 Logo \ 123.GIF" style = "height: 71px; Width: 400px; Border-width: 0px; "

Unfortunately, you can not use the source of the" file: "URL Image.You need to turn that path into a valid HTTP URL.

So if your images are in "c: \ online reporting \ SQL solution" , then you In an IIS virtual directory that is under your site root, which indicates there, maybe it's called "/ logo" or something, you can go:

string filename = path. GET filename (rea Der.GetString (0)); Image1.ImageUrl = "/ Logo /" + filename;

If your web root is already running, say "c: \ online" Reporting ", it is much easier - you can leave the virtual directory and simply" / SQL% 20Solutions "as the beginning of the URL.


No comments:

Post a Comment