심재운 블로그



1, Create a XML document named "Medias.xml"

<?xml version="1.0" encoding="utf-8" ?>
<medias>
    <media>
        <ID>1</ID>
        <Name>Gallery 1</Name>
        <Folder>~/media/mypath2us</Folder>
        <Owner>1</Owner>
    </media>
</medias>



 

 

2, Create a class to represent the Media object...

public class Media
{
    public Media()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public Media(int nID, string strName, string strFolderUrl, int nOwnerID)
    {
        //
        // TODO: Add constructor logic here
        //
        this.ID = nID;
        this.Name = strName;
        this.FolderUrl = strFolderUrl;
        this.OwnerID = nOwnerID;
    }

    public int ID { get; set; }

    public string Name { get; set; }

    public string FolderUrl { get; set; }

    public int OwnerID { get; set; }

}





3, Load the document using System.Xml.Linq ...

XElement rootElement = XElement.Load(Server.MapPath("~/Medias.xml"));
 var q = from media in rootElement.Descendants("media")
           select new Media((int)media.Element("ID"), (string)media.Element("Name"), (string)media.Element("Folder"), (int)media.Element("Owner"));

  this.rptGalleries.DataSource = q; //Bind the result to a repeater control.
  this.rptGalleries.DataBind();




 

이 글을 공유합시다

facebook twitter kakaoTalk kakaostory naver band

본문과 관련 있는 내용으로 댓글을 남겨주시면 감사하겠습니다.

비밀글모드