473,498 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

xml doc upload code for you

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
Nov 18 '05 #1
0 840

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
11735
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
2
6045
by: Tom Wells | last post by:
I have a little file upload page that I have been able to use to successfully upload files to the C: drive of LocalHost (my machine). I need to be able to upload to a network drive from the intranet...
9
3813
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web...
4
9663
by: Marko Vuksanovic | last post by:
I am trying to cause the uplaod button, id="Upload",when clicked, to exectue the onClick event for Button1, id="Button1". <asp:FileUpload id="FileUpload" runat="server"> </asp:FileUpload>...
3
23030
acoder
by: acoder | last post by:
How to Upload a File in Coldfusion Use the cffile tag for uploading files to the server. Note that allowing people to upload files is fraught with danger and only trusted users should be...
9
20874
by: 8anos | last post by:
Hello, I am new at the community and newbie at programming :) As you may know rapidshare provides a perl script for linux, to upload files at their servers. You can find the original scripts at...
21
34316
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
2
7625
by: hotflash | last post by:
Hi All, I found the best pure ASP code to upload a file to either server and/or MS Access Database. It works fine for me however, there is one thing that I don't like and have tried to fix but...
5
3260
by: camphor | last post by:
hi, I have found an upload script in hotscripts and have implemented it into the website, I followed the installation steps to 'give write permissions to php on the upload folder (which is...
1
4853
by: chennaibala | last post by:
can any one send me mutiple image upload program and save the file name with extension in mysql table.we must cheak uploaded file type like bmp or any image file while uploading. i develop...
0
7125
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7002
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7203
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4908
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4588
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3081
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1417
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
290
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.