链接到xml文件中的图像位置

本文关键字:图像 位置 文件 xml 链接 | 更新日期: 2023-09-27 18:01:03

我在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;
       } 
   } 
}

}

链接到xml文件中的图像位置

在看了一点导入数据后,我发现它似乎只将数据作为纯字符串导入。我甚至探索过使用"=HYPERLINK(("函数,但它被导入为文本,并且不会进行计算。

根据您的需要,有几种可能的解决方案。

选项1:您可以创建一个excel文件,而不是xml文件。然而,这很复杂,可能有点麻烦。

选项1.1:您可以创建并excel xml文件。通过将工作表保存为xml,然后查看xml并编写一些代码来重新创建它,您可以看到这些是如何布局的

选项2:如果你是将数据导入excel文件的人,那么你可以通过选择数据来运行宏或vb脚本,将其转换为链接。