Hi monzer,
Please refer below sample.
HTML
<div>
<asp:FileUpload ID="FileUpload1" runat="server" />
<br />
<br />
title :
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<br />
link :<asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
<br />
description:
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
<br />
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="Button3_Click" />
</div>
Namespaces
C#
using System.Xml.Linq;
using System.IO;
using System.Xml;
VB.Net
Imports System.IO
Imports System.Xml
Code
C#
protected void Button3_Click(object sender, EventArgs e)
{
string FilePath;
int size = 5230000;
string attac1;
FilePath = "D:\\site1\\xmlfile1.xml";
XDocument document = new XDocument();
if (File.Exists(FilePath))
{
document = XDocument.Load(FilePath);
}
else
{
Label1.Text = "! لم تتم اللاضافة";
}
if ((FileUpload1.HasFile == true))
{
if ((FileUpload1.PostedFile.ContentLength <= size))
{
string strPath;
strPath = ("~/files/" + FileUpload1.FileName);
FileUpload1.SaveAs(MapPath(strPath));
}
}
attac1 = FileUpload1.FileName;
XmlDocument doc = new XmlDocument();
doc.Load(FilePath);
XmlNode node = doc.SelectSingleNode("rss/channel");
XmlNode item = doc.CreateNode(XmlNodeType.Element, "item", null);
XmlNode title = doc.CreateNode(XmlNodeType.Element, "title", TextBox3.Text);
item.AppendChild(title);
XmlNode pubDate = doc.CreateNode(XmlNodeType.Element, "pubDate", DateTime.Now.ToString("yyy/MM/dd HH:mm"));
item.AppendChild(pubDate);
XmlNode description = doc.CreateNode(XmlNodeType.Element, "description", TextBox5.Text);
item.AppendChild(description);
XmlNode thumbnail = doc.CreateNode(XmlNodeType.Element, "link", TextBox6.Text);
XmlNode mediathumbnail = doc.CreateNode(XmlNodeType.Element, "media.thumbnail", TextBox6.Text);
XmlNode url = doc.CreateNode(XmlNodeType.Element, "url", "http://karary-001-site1.htempurl.com/files/" + (attac1 + "?itok=YdFLolAU"));
XmlNode height = doc.CreateNode(XmlNodeType.Element, "height", "266");
XmlNode width = doc.CreateNode(XmlNodeType.Element, "width", "127");
url.AppendChild(height);
url.AppendChild(width);
mediathumbnail.AppendChild(url);
thumbnail.AppendChild(mediathumbnail);
item.AppendChild(thumbnail);
node.AppendChild(item);
doc.DocumentElement.AppendChild(node);
doc.Save(FilePath);
Label1.Text = "! done";
}
VB.Net
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim FilePath As String
Dim size As Integer = 5230000
Dim attac1 As String
FilePath = "D:\site1\xmlfile1.xml"
Dim document As XDocument = New XDocument()
If File.Exists(FilePath) Then
document = XDocument.Load(FilePath)
Else
Label1.Text = "! لم تتم اللاضافة"
End If
If (FileUpload1.HasFile = True) Then
If (FileUpload1.PostedFile.ContentLength <= size) Then
Dim strPath As String
strPath = ("~/files/" & FileUpload1.FileName)
FileUpload1.SaveAs(MapPath(strPath))
End If
End If
attac1 = FileUpload1.FileName
Dim doc As XmlDocument = New XmlDocument()
doc.Load(FilePath)
Dim node As XmlNode = doc.SelectSingleNode("rss/channel")
Dim item As XmlNode = doc.CreateNode(XmlNodeType.Element, "item", Nothing)
Dim title As XmlNode = doc.CreateNode(XmlNodeType.Element, "title", TextBox3.Text)
item.AppendChild(title)
Dim pubDate As XmlNode = doc.CreateNode(XmlNodeType.Element, "pubDate", DateTime.Now.ToString("yyy/MM/dd HH:mm"))
item.AppendChild(pubDate)
Dim description As XmlNode = doc.CreateNode(XmlNodeType.Element, "description", TextBox5.Text)
item.AppendChild(description)
Dim thumbnail As XmlNode = doc.CreateNode(XmlNodeType.Element, "link", TextBox6.Text)
Dim mediathumbnail As XmlNode = doc.CreateNode(XmlNodeType.Element, "media.thumbnail", TextBox6.Text)
Dim url As XmlNode = doc.CreateNode(XmlNodeType.Element, "url", "http://karary-001-site1.htempurl.com/files/" & (attac1 & "?itok=YdFLolAU"))
Dim height As XmlNode = doc.CreateNode(XmlNodeType.Element, "height", "266")
Dim width As XmlNode = doc.CreateNode(XmlNodeType.Element, "width", "127")
url.AppendChild(height)
url.AppendChild(width)
mediathumbnail.AppendChild(url)
thumbnail.AppendChild(mediathumbnail)
item.AppendChild(thumbnail)
node.AppendChild(item)
doc.DocumentElement.AppendChild(node)
doc.Save(FilePath)
Label1.Text = "! done"
End Sub