hii All,
I wants to Create XML File DYnamically Using ASP.Net C# which retrieves data from sql server database.
Also I wants that To delete / Create Xml files on server Just By Clicking a button...

Thankyou....

Dani AI

Generated

Below are concrete, production-minded steps and short C# helpers to satisfy 's requirement to generate an XML file on login and delete it on logout (while tying back to 's suggestion to learn the basics). The approach keeps files out of the web root (App_Data), uses a unique sanitized name (user id), handles SQL retrieval safely, and calls the helpers from the login/logout handlers. Prefer storing the data in the database or session if the filesystem file is not strictly required.

using System;
using System.Data.SqlClient;
using System.IO;
using System.Web;
using System.Xml.Linq;

public static class XmlHelper
{
    public static string CreateEmployeeXml(int userId, string connString)
    {
        string folder = HttpContext.Current.Server.MapPath("~/App_Data/GeneratedXml");
        Directory.CreateDirectory(folder);
        string fileName = "user_" + userId.ToString() + ".xml";
        string path = Path.Combine(folder, fileName);

        using (var conn = new SqlConnection(connString))
        using (var cmd = new SqlCommand("SELECT EmployeeID, FullName, Email FROM Employees WHERE EmployeeID = @id", conn))
        {
            cmd.Parameters.AddWithValue("@id", userId);
            conn.Open();
            using (var rdr = cmd.ExecuteReader())
            {
                if (!rdr.HasRows) return null;
                var doc = new XDocument(new XElement("Employee"));
                if (rdr.Read())
                {
                    doc.Root.Add(new XElement("EmployeeID", rdr["EmployeeID"]),
                                 new XElement("FullName", rdr["FullName"]),
                                 new XElement("Email", rdr["Email"]));
                }
                doc.Save(path);
            }
        }
        return path;
    }

    public static void DeleteEmployeeXml(int userId)
    {
        string folder = HttpContext.Current.Server.MapPath("~/App_Data/GeneratedXml");
        string path = Path.Combine(folder, "user_" + userId.ToString() + ".xml");
        if (File.Exists(path)) File.Delete(path);
    }
}

Example wiring: call CreateEmployeeXml after authentication succeeds (Login control OnLoggedIn or custom auth flow). Call DeleteEmployeeXml in the explicit logout handler before signing out. Do not rely on Session_End unless using InProc session state; for out-of-process sessions use a scheduled cleanup task that removes files older than a safe threshold.

Troubleshooting & cautions: ensure the ASP.NET process identity has write permission to App_Data; sanitize any user data used in filenames to avoid path injection; avoid storing sensitive PII in plain XML (encrypt or store in DB instead); handle exceptions and log failures; implement a background cleanup for abandoned files to prevent disk buildup.

Recommended Answers

All 5 Replies

hii All,
I wants to Create XML File DYnamically Using ASP.Net C# which retrieves data from sql server database.
Also I wants that To delete / Create Xml files on server Just By Clicking a button...

Thankyou....

Its a problem to guide you step by step because we dont know what you want in your xml,
But you can learn:
http://www.w3schools.com/xml/default.asp
This is a very easy to learn tutorial so learn and if you have questions ask again.

Its a problem to guide you step by step because we dont know what you want in your xml,
But you can learn:
http://www.w3schools.com/xml/default.asp
This is a very easy to learn tutorial so learn and if you have questions ask again.

Actually I wants to store simple data of employee into xml file i.e at the time when user log in then an xml file will automatically generated....and after user logouts this file will be deleted...plzz solve this problem....

Actually I wants to store simple data of employee into xml file i.e at the time when user log in then an xml file will automatically generated....and after user logouts this file will be deleted...plzz solve this problem....

What are you tring to accomplish with that?

What are you tring to accomplish with that?

I have received this assignment from my boss...plzz tell me if you know..

I have received this assignment from my boss...plzz tell me if you know..

Yes ok,

But maybe there is a better way to do it, because I can't figure out for what do you need it, I really tring to help you.
Maybe your boss don't understand in web application and want's somthing that can achieved in a better way.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.