Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to get images dynamically from database without file paths in the table field

New Here ,
Dec 04, 2010 Dec 04, 2010

I have a MS-Access database. I am working with ASP.NET. In the database there is product table in which I have "CodeNo" as a field which is a text field, and the product codes like "SM-R-2035". I also have another field "Image" which is also a text field and which have a file path in it corresponding to the particular product Image (e.g. Images\Products\SM-R-2035.jpg). So far every thing is ok. I have to update this site very frequently and lots of images are added each and every time. Its a tedious work to type the paths and file name every time and it also take a lot of time.

What I am asking is : Is it possible to get images from a specific folder at runtime which is referenced by the "code no" itself and not the file path from the database. (Say at run time the "code no" is referenced from the database and the corresponding image is loaded dynamically from the specified folder). In other word I want to avoid the tedious work of typing.

Can any one help with this issue. Any other simple suggestions are welcome.

TOPICS
Server side applications
2.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 04, 2010 Dec 04, 2010

Hi

Don't know if this is possible using an access database for the web, but you could use a look-up table just to prepend the file path to the image name.

See - http://www.trigonblue.com/AccessLookup.htm

Just have the file path in the access table as a separate entry and concat the file name to this, or have the file path hard coded into your html code as required.

PZ

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 06, 2010 Dec 06, 2010

Thanks pziecina !

Your suggestions are welcome I am looking forward to it. "Lookup" might not work but concatenating field values at runtime is definitely worth a try. Thanks !

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 06, 2010 Dec 06, 2010

All you need to do is simple concatenation to obtain the path for the image file.  You didn't mention whether you are using VB.Net, C# or some other language to do your coding.

If the code in your database is SM-R-2035, the file name is SM-R-2035.jpg and the path to the images foilder is Images\Products\SM-R-2035.jpg, Conceptually here is what you need to do:

dim code_var

dim path_var


code_var = the code you obtain from your relevant field in the database


path_var = "Images\Products\" & code_var & ".jpg"

Now path_var is what you would call to obtain the image from your images folder.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 06, 2010 Dec 06, 2010

Thanks Ultarsuit !

I am using VB.NET. But let me also admit that basically I am a designer and not a programmer. So writing some code for me is just like rocket science. Right now I am using Excel to concatenate the field values to get the path string and then using an "import external data" wizard in access to get that data.

You have suggested me the steps that I need to write the code in my .aspx document. I use dreamweaver's GUID by which I can place the recordset in my .aspx document visually (Just drag and drop or just click insert and dreamweaver does all coding for me)

Although I got the idea of declaring the variables and then concatenating the field values to get the string. I will definitely try and workout.

Thank you once again !

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 15, 2010 Dec 15, 2010

Were you able to make the concatenation work?

J.S.

http://ultrasuite.blogspot.com/

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 16, 2010 Dec 16, 2010

Hi,

I am working on it. I am getting the string (path) correct when testing with Response.Write. But don't know to bind this path to image. Write now I am out of my office, so am not able to provide code. I will post the code in a day or two. Thank you for your kind guidance.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 26, 2010 Dec 26, 2010

Here is my code :

<script runat="server">

Sub Page_Load( )

Dim fileName As String = Server.MapPath("Products\") &  dsproducts.FieldValue("CodeNo", Nothing) & ".jpg"

<img src="<%= fileName %>" width="96" height="96" id="image" />

End Sub

</script>

When I use Response.Write(fileName) I get the correct path

i.e. D:\WebSites\Testing Project\ASPdotNet\Products\SM-R-1232.jpg

But binding it to image is not working. Can you please guide me how to get it done.

Thank you in advance.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 08, 2011 Jan 08, 2011

Your image path doesn't conform to the requirememts of HTML  The browser is not interested that the image is on D drive.  It needs a proper path like http://domain.com/path/image.jpg

J.S.

http://www.ultrasuite.com/
http://twitter.com/dwUltraSuite

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 08, 2011 Jan 08, 2011
LATEST

MapPath is used to obtain the physical address of a resource. You don't want to use it for this. As J.S. suggests, it's not valid for a url. Just use the doc or root relative path.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines