Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6762931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:25:01+00:00 2026-05-26T14:25:01+00:00

I have written code in C# that should transform an XML with the help

  • 0

I have written code in C# that should transform an XML with the help of a XSL stylesheet, generate some HTML and save it locally where the XML and XSL are there, then send the HTML as e-mail.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web.Mail;
using System.Text;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;

public class SendMail
{
   static void Main(string[] args)
   {
     {       
       try{

         //load the Xml doc
         XPathDocument XPathDoc = new XPathDocument(@"C:\Test\svnlog.xml") ;

         XslTransform XslTrans = new XslTransform() ;

         //load the Xsl 
         XslTrans.Load(@"C:\Test\svnlog.xsl") ;

         //create the output stream
         XmlTextWriter Writer = new XmlTextWriter(@"C:\Test\CommitReport.html", null);

        //do the actual transform of Xml
        XslTrans.Transform(XPathDoc,null, Writer);        

        Writer.Close() ;

          }
      catch(Exception ex)
    {

        Response.Write(ex.Message);
    }


  using (StreamReader reader = File.OpenText(@"C:\Test\CommitReport.html"))
{                                                         
   MailMessage Mail = new MailMessage();
   Mail.To = ("pqr@dna.com "); 
   Mail.From = new MailAddress("abc@bac.com");
   Mail.Subject = ("Commit Error Report"); 
   Mail.IsBodyHtml = true;  //defines that your email is in Html form 
   Mail.BodyFormat = (@"C:\Test\CommitReport.html"); 

  Mail.Body = reader.ReadToEnd(); 
}

 //create instance of smtpclient 
 SmtpClient smtp = new SmtpClient(); 
 smtp.EnableSsl = true; 
 smtp.Send(mail);

 } 

 }

  private static void MailAddress(string p)
{
        throw new NotImplementedException();
}

 }

I am not sure whether the following line saves the html locally or not:

XmlTextWriter Writer = new XmlTextWriter(@"C:\Test\CommitReport.html", null); 

I am also getting a new error: “The type or namespace name ‘Mail’ does not exist in the namespace ‘System.Web’ (are you missing an assembly reference?)”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:25:01+00:00Added an answer on May 26, 2026 at 2:25 pm

    The SmtpClient class is defined in the System.Net.Mail namespace, not System.Web.Mail. Your code needs some modifications. For example things like Response.Write(ex.Message); in a console application hardly make sense. Ensuring proper disposal of disposable resources is also important.

    So try improving your code a little:

    using System;
    using System.IO;
    using System.Net.Mail;
    using System.Xml;
    using System.Xml.XPath;
    using System.Xml.Xsl;
    
    class Program
    {
        static void Main()
        {
            try
            {
                var xPathDoc = new XPathDocument(@"C:\Test\svnlog.xml");
                var xslTrans = new XslCompiledTransform();
                xslTrans.Load(@"C:\Test\svnlog.xsl");
                using (var writer = XmlWriter.Create(@"C:\Test\CommitReport.html"))
                {
                    xslTrans.Transform(xPathDoc, null, writer);
                }
    
                var mail = new MailMessage();
                mail.To.Add(new MailAddress("pqr@dna.com"));
                mail.From = new MailAddress("abc@bac.com");
                mail.Subject = "Commit Error Report";
                mail.IsBodyHtml = true;
                mail.Body = File.ReadAllText(@"C:\Test\CommitReport.html");
    
                using (var smtpClient = new SmtpClient("smtp.yourhost.com"))
                {
                    smtpClient.EnableSsl = true;
                    smtpClient.Send(mail);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
    

    Also make sure that

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written some code to ensure that items on an order are all
I have a c++ source code that was written in linux/unix environment by some
I have some old code written in C for 16-bit using Borland C++ that
I have written some code that uses attributes of an object: class Foo: def
I have written some code that makes use of an open source library to
I have written some custom R code that wraps a third-party binary. One of
I have written down a code that should do garbage collection for c programs.
I am running some code that I have written in C which calls the
I have written code within Python that doesn't release memory the way it should.
I have written code that automatically creates CSS sprites based on the IMG tags

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.