如何在Asp.net中使用XML存储和检索图像 [英] How to Store And Retrieve Image Using XML in Asp.net

查看:109
本文介绍了如何在Asp.net中使用XML存储和检索图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hii专家,
我正在做一个将数据和图像存储在附加到应用程序的XML文件中的项目.绑定网格视图的图像.也想修改(编辑/删除)数据.我可以将数据存储在xml文件中,但不能存储图像文件.以下是我的代码

Hii Experts,
I am doing a project that will store data as well as Image in an XML file attached to the application.And fetch data & Image to bind a gridview.Also want to modify(edit/delete) data.I am able to store data in xml file but not able to store image file.below is my code

Dim myXmlDocument As New System.Xml.XmlDocument()
       myXmlDocument.Load(Server.MapPath("XMLFile2.xml"))
       Dim myXmlNode As System.Xml.XmlNode = myXmlDocument.DocumentElement.FirstChild
       ' Create new XML element and populate its attributes
       Dim myXmlElement As System.Xml.XmlElement = myXmlDocument.CreateElement("entry")
       myXmlElement.SetAttribute("Name", Server.HtmlEncode(txtName.Text))
       myXmlElement.SetAttribute("Location", Server.HtmlEncode(txtAddress.Text))
       myXmlElement.SetAttribute("Email", Server.HtmlEncode(txtEmail.Text))



有没有解决此问题的方法.请解决我的问题



Is there any solution to this problem.Kindly solve My problem

推荐答案

使用数据表(或更多数据)创建一个DataSet并使用从以下位置加载 [
Create a DataSet with a table (or more) for your data and use the save to[^]/load from[^] XML capabilities.

I guess this would be the easiest way to do it :)

Regards
Espen Harlinn


您需要将图像转换为String,因为XML不支持直接二进制数据.

我建议您将其编码为Base64(Convert.ToBase64String()).

问候,
大卫
You need to convert the image into a String, since XML does not support direct binary data.

I suggest you encode it into Base64 (Convert.ToBase64String()).

Regards,
David


这篇关于如何在Asp.net中使用XML存储和检索图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆