【发布时间】:2015-09-20 22:41:41
【问题描述】:
我在 C# 中使用 xmlwriter 创建一个 xml 文件,用于保存俱乐部成员的记录。 我想在每个成员的记录中存储一个指向将存储在文件夹中的个人身份证照片位置的链接。
private void button1_Click(object sender, EventArgs e)
{
string documentPath = @"D:\Book6.xml";
XmlDocument myxDoc = new XmlDocument();
myxDoc.Load(documentPath);
//Member Node creation
XmlNode member = myxDoc.CreateElement("Member");
//XmlNode information = myxDoc.CreateElement("Information");
XmlNode name = myxDoc.CreateElement("Name");
name.InnerText = txtName.Text;
member.AppendChild(name);
//
XmlNode dateofbirth = myxDoc.CreateElement("DateofBirth");
dateofbirth.InnerText = txtDOB.Text;
member.AppendChild(dateofbirth);
//
XmlNode idnumber = myxDoc.CreateElement("IdNumber");
idnumber.InnerText = txtID.Text;
member.AppendChild(idnumber);
//
XmlNode address = myxDoc.CreateElement("Address");
address.InnerText = txtAddress1.Text;
member.AppendChild(address);
//
XmlNode contactnumber = myxDoc.CreateElement("ContactNumber");
contactnumber.InnerText = txtCellnumber.Text;
member.AppendChild(contactnumber);
//
XmlNode email = myxDoc.CreateElement("Email");
email.InnerText = txtEmail.Text;
member.AppendChild(email);
//
XmlNode designation = myxDoc.CreateElement("Designation");
designation.InnerText = txtDesignation.Text;
member.AppendChild(designation);
//
XmlNode branch = myxDoc.CreateElement("Branch");
branch.InnerText = txtBranch.Text;
member.AppendChild(branch);
//
XmlNode province = myxDoc.CreateElement("Province");
province.InnerText = txtProvince.Text;
member.AppendChild(province);
//
XmlNode district = myxDoc.CreateElement("District");
district.InnerText = txtDistrict.Text;
member.AppendChild(district);
//
XmlNode constituency = myxDoc.CreateElement("Constituency");
constituency.InnerText = txtConstituency.Text;
member.AppendChild(constituency);
//
XmlNode formnumber = myxDoc.CreateElement("FormNumber");
formnumber.InnerText = txtFormNum.Text;
member.AppendChild(formnumber);
//
XmlNode subscription = myxDoc.CreateElement("Subscription");
subscription.InnerText = txtSubscripton.Text;
member.AppendChild(subscription);
//
XmlNode period = myxDoc.CreateElement("Period");
period.InnerText = txtPeriod.Text;
member.AppendChild(period);
//
XmlNode image = myxDoc.CreateElement("Image");
image.InnerText = txtName.Text;//imageLocation; //imagePhoto.ToString();
member.AppendChild(image);
//member.AppendChild(information);
myxDoc.DocumentElement.AppendChild(member);
myxDoc.Save(documentPath);
txtName.Text = String.Empty;
txtDOB.Text = String.Empty;
txtID.Text = String.Empty;
txtAddress1.Text = String.Empty;
txtAddress2.Text = String.Empty;
txtAddress3.Text = String.Empty;
txtCellnumber.Text = String.Empty;
txtEmail.Text = String.Empty;
txtDesignation.Text = String.Empty;
txtBranch.Text = String.Empty;
txtProvince.Text = String.Empty;
txtDistrict.Text = String.Empty;
txtConstituency.Text = String.Empty;
txtFormNum.Text = String.Empty;
txtSubscripton.Text = String.Empty;
txtPeriod.Text = String.Empty;
txtWard.Text = String.Empty;
}
private void btnPhoto_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
//filters
open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
if (open.ShowDialog() == DialogResult.OK)
{
imagePhoto.Image = new Bitmap(open.FileName);
imagePhoto.SizeMode = PictureBoxSizeMode.StretchImage;
imageLocation = open.FileName;
}
}
}
}
【问题讨论】:
-
您有具体问题还是只是告诉我们您在做什么?
-
对不起,是的,问题是当我在 excel 中打开 xml 文件时,如何使文件位置作为链接打开
-
@leppie 是的,我需要有关如何使其成为链接的帮助,以便当我在 excel 中打开 xml 时,它是一个有效的活动链接
标签: c# xml image hyperlink directory