xml doc upload code for you

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Girish (girishkiss_at_yahoo.com)
Date: 02/20/04


Date: Fri, 20 Feb 2004 09:20:50 -0800

Hi Guys

Enjoy the xml upload code I believe which I got from my SERVICE PROVIDER,
Now do me a favor back, can you please translate it to ASP ?

=======================================
private enum ReturnCode { Success, Error, NoData, FileIOError };

      private void Page_Load(object sender, System.EventArgs e)

      {

            ReturnCode returnCode = ReturnCode.Success;

            try

            {

                  returnCode = Upload();

            }

            catch

            {

                  returnCode = ReturnCode.Error;

            }

            finally

            {

                  Response.Output.Write(
"<result><returnCode>{0}</returnCode></result>", returnCode );

            }

      }

      private ReturnCode Upload()

      {

            ReturnCode returnCode = ReturnCode.Success;

            //

            // Make sure we have something to work with

            //

            int bLen = Context.Request.ContentLength;

            if( bLen > 0 )

            {

                  //

                  // The body contains XML formatted as ADF...

                  // so convert the bytes to string.

                  //

                  byte[] bytes = Context.Request.BinaryRead( bLen );

                  string msg = Encoding.ASCII.GetString( bytes, 0,
bLen );

                  //

                  // At this point we have some data and we expect

                  // it to be an ADF report, which is valid XML.

                  //

                  NameTable nt = new NameTable();

                  XmlNamespaceManager nsmgr = new
XmlNamespaceManager( nt );

                  XmlParserContext pc = new
XmlParserContext( null, nsmgr, null, XmlSpace.None );

                  XmlValidatingReader xmlReader = new XmlValidatingReader(
msg, XmlNodeType.Document, pc );

                  //

                  // The Microsoft XML parser cannot resolve the

                  // colorcombination element... so for now, just

                  // disable the validation.

                  //

                  xmlReader.ValidationType = ValidationType.None;

                  //

                  // Load the document

                  //

                  XPathDocument xDoc = new XPathDocument( xmlReader );

                  XPathNavigator nav = xDoc.CreateNavigator();

                  //

                  // Find the call id so that we can use it as a filename.

                  //

                  string cdrID = null;

                  XPathNodeIterator iter = nav.Select( "/adf/prospect" );

                  while( iter.MoveNext() && cdrID == null )

                  {

                        XPathNodeIterator prospectIter =
iter.Current.SelectChildren( XPathNodeType.Element );

                        while( prospectIter.MoveNext() )

                        {

                              if( string.Compare( prospectIter.Current.Name,
"id", true ) == 0 )

                              {

                                    cdrID = prospectIter.Current.Value;

                                    break;

                              }

                        }

                  }

                  try

                  {

                        if( cdrID != null )

                        {

                              string dir =
ConfigurationSettings.AppSettings[ "DataFileDir" ];

                              if( dir == null || dir.Length == 0 )

                              {

                                    // default to the current directory

                                    dir = ".";

                              }

                              string fileName = string.Format(
@"{0}\{1}.xml", dir, cdrID );

                              using( StreamWriter writer =

                                                new StreamWriter( new
FileStream( fileName, FileMode.Create ),

                                              System.Text.Encoding.ASCII ) )

                              {

                                    writer.WriteLine( msg );

                              }

                        }

                  }

                  catch

                  {

                        returnCode = ReturnCode.FileIOError;

                  }

            }

            else

            {

                  returnCode = ReturnCode.NoData;

            }

            return returnCode;

      }

=======================================

Thanks

G



Relevant Pages

  • Send email from ASP
    ... from my web site using ASP. ... or third-party) or SMTP server. ... One way to do it could be to set up a html form with fields to hold ... and body) and send it to the service provider. ...
    (microsoft.public.inetserver.asp.general)
  • Re: HTTP GET - VBscript help?
    ... I have a service provider that's sends sms messages from clients mobile ... phones to my asp page, problem is I don't know how to show the data and ... The above applies as VBScript within your ASP page. ...
    (microsoft.public.scripting.vbscript)
  • Re: Blank form being submitted
    ... Because it ASP no one from this end can see ... the code because it is translate. ... *SLAP* Gotcha! ... Prev by Date: ...
    (microsoft.public.inetserver.asp.db)
  • Re: Examples for attacks on ASPs
    ... I do not mean ASP as Application Server Pages, ... Service Provider. ... the last is a business-model. ... Your Google query delivers results for the first one. ...
    (comp.security.misc)
  • Re: Encrypt in C++ and ASP...
    ... i've been programming ASP for a few years, ... I need to translate a piece of C++ code which encrypts a string into ... Calling this function Encryption is quite a stretch, ...
    (microsoft.public.vc.language)