Microsoft KB Archive/310290

= How to add a text file to a computer that is running IIS in Visual C# =

Article ID: 310290

Article Last Modified on 1/19/2006

-

APPLIES TO


 * Microsoft Visual C# 2005 Express Edition
 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft Visual C# .NET 2002 Standard Edition
 * Microsoft Exchange 2000 Server Standard Edition
 * Microsoft Internet Information Services 6.0
 * Microsoft XML Core Services 4.0
 * Microsoft XML Core Services 4.0

-



This article was previously published under Q310290



SUMMARY
This article describes how to use Microsoft XML 3.0 or Microsoft XML 4.0 to add a text file to a computer that is running Microsoft Internet Information Services (IIS) in Microsoft Visual C#.



MORE INFORMATION
To add a text file, follow these steps:  Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005. On the File menu, point to New, and then click Project. In the Visual C# Projects types list, click Console Application.

Note In Visual Studio 2005, click Visual C# in the Visual C# Projects type.

In Visual Studio .NET, Class1.cs is created by default. In Visual Studio 2005, Program.cs is created by default. Add a reference to Microsoft XML 3.0 or to Microsoft XML 4.0. To do so, follow these steps:  On the Project menu, click Add Reference. Click the COM tab, locate XML 3.0 or XML 4.0, and then click Select.

Note In Visual Studio 2005, you do not have to click Select. In the Add References dialog box, click OK.</li> If you are prompted to generate wrappers for the libraries that you selected, click Yes.</li></ol> </li>  In the code window, replace the code with the following: using System; using System.Reflection;

namespace WebDav { class Class1 {        public static void Main(String [] args) {         try {                         MSXML2.XMLHTTP30 oXMLHttp = new MSXML2.XMLHTTP30; // TODO: Change the URL, userid, and password to reflect your environment. String sUrl = &quot;http://IISServer/VirtualDirectory/Test.xml&quot;; oXMLHttp.open(&quot;PUT&quot;, sUrl, false, &quot;UserDomain\UserAlias&quot;, &quot;UserPassword&quot;); //TODO: Build a string to be put on the IIS server String sXml; sXml = &quot;<?xml version=\&quot;1.0\&quot;?>&quot;; sXml = sXml + &quot; &quot;; sXml = sXml + &quot; User1 Test &quot;; sXml = sXml + &quot; User2 Test &quot;; sXml = sXml + &quot; &quot;; oXMLHttp.setRequestHeader(&quot;Content-Type&quot;, &quot;text/xml&quot;); oXMLHttp.setRequestHeader(&quot;Content-Length&quot;, &quot;&quot; + sXml.Length);

oXMLHttp.send(sXml); Console.WriteLine(oXMLHttp.status); Console.WriteLine(oXMLHttp.statusText); Console.WriteLine(oXMLHttp.responseText); }        catch (Exception e)             { Console.WriteLine(&quot;{0} Exception caught.&quot;, e); }

}   } } </li> Search for TODO in the code, and then modify the code for your environment.</li> Press F5 to build and to run the program.</li> Make sure that the file has been added to the computer that is running IIS.</li></ol>

<div class="references_section">