473,473 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Getting an XML file served from aspx

gchq
96 New Member
Hi there

The issue

Need to bring in an XML file to the App that is not in the App root.

Part Solution

I have built an aspx page that will bring in the XML file and 'serve' it

Expand|Select|Wrap|Line Numbers
  1. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  2.         Dim GetFile As String
  3.         GetFile = "\\Interclaims1\InterclaimsC\Data\Shared\XML\Parkwood\Newsletter.xml"
  4.         If New System.IO.FileInfo(GetFile).Exists Then
  5.             Response.Clear()
  6.             Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches)
  7.             Response.ContentType = "text/xml"
  8.             Response.ContentEncoding = Encoding.UTF8
  9.             Response.WriteFile(GetFile)
  10.             Response.End()
  11.         End If
  12.  
  13.     End Sub
This runs without a problem and shows the XML content

Now I need to to use xml events to get a value from that XML file

Expand|Select|Wrap|Line Numbers
  1. Dim xmldoc As New XmlDataDocument
  2.             Dim vXmlNode As XmlNode
  3.             xmldoc.Load(Server.MapPath(vmapxmlpath))
  4.             Dim xmlnodelist As XmlNodeList = xmldoc.DocumentElement.SelectNodes("NewsLetter_Data")
  5.             For Each vXmlNode In xmlnodelist
  6.                 Dim vType As Integer = vXmlNode.SelectSingleNode("Newsletter_ID").InnerText
  7.                 If vType = 2 Then
  8.                     Dim vReplaceText As New ReplaceText
  9.                     Dim vConverted As String = vReplaceText.ReturnHTML(vXmlNode("NewsLetter_Body").InnerText)
  10.                     TextBox1.Text = vConverted
  11.                 End If
  12.             Next
Sooooooo the question is how do I create a valid MapPath so that it loads the document correctly?

Dim vmapxmlPath as string = "ServeXML.aspx"

causes an error = it needs to resolve the url to get the file, but I can't figure out the correct syntax....
Feb 7 '08 #1
1 938
gchq
96 New Member
Think I have found a way round this - to set up a local temp directory, then write a class to get the original xml document and save it to the local temp dir - this can then be accessed by the page that wants to select, insert or update changes to it, then call the class again to move the file...

Here is the class

Expand|Select|Wrap|Line Numbers
  1. Public Sub GetXmlFile()
  2.         Dim GetFile As String
  3.         GetFile = "\\Interclaims1\InterclaimsC\Data\Shared\XML\Parkwood\Newsletter.xml"
  4.         If New System.IO.FileInfo(GetFile).Exists Then
  5.  
  6.             Dim vPath As String = HttpContext.Current.Server.MapPath("..\XML\XML_Temp\Newsletter_Temp2.xml")
  7.             Dim objFile As System.IO.File
  8.             Dim strSource As String = GetFile
  9.             Dim strDest As String = vPath
  10.             If objFile.Exists(strDest) Then
  11.                 objFile.Delete(strDest)
  12.             End If
  13.             objFile.Copy(strSource, strDest)
  14.         End If
  15.     End Sub
  16.  
  17.     Public Sub SaveFile()
  18.         Dim vPath As String = HttpContext.Current.Server.MapPath("..\XML\XML_Temp\Newsletter_Temp2.xml")
  19.         If New System.IO.FileInfo(vPath).Exists Then
  20.             'copy the file back to the central location
  21.             Dim objFile As System.IO.File
  22.             Dim strSource As String = vPath
  23.             Dim strDest As String = "\\Interclaims1\InterclaimsC\Data\Shared\XML\Parkwood\Newsletter.xml"
  24.             Dim strBackup As String = "\\Interclaims1\InterclaimsC\Data\Shared\XML\Parkwood\Newsletter_Backup.xml"
  25.             If objFile.Exists(strBackup) Then
  26.                 objFile.Delete(strBackup)
  27.             End If
  28.             objFile.Copy(strDest, strBackup)
  29.             If objFile.Exists(strDest) Then
  30.                 objFile.Delete(strDest)
  31.             End If
  32.             objFile.Move(strSource, strDest)
  33.         End If
  34.  
  35.     End Sub
Bit long winded, but it does work....
Feb 8 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Amittai Aviram | last post by:
(Slightly OT.) Does anybody here who works in both PHP and Perl happen to know whether there is a Perl equivalent to PHP's file(url)? I need to get the HTML output of a file as served through...
7
by: Lorenzo Vaina | last post by:
Can i get the content of an URL and put it in a variable using javascript? I want js execute different operations varying a file that is on internet. Thanks, regards.
7
by: theyas | last post by:
How can I get my code to NOT display two "Open/Save/Cancel/More Info" dialog boxes when using the "Response.WriteFile" method to download a file to IE I've asked about this before and didn't get a...
5
by: Kikoz | last post by:
Hi all. I assume that if the user uploads a file from aspx page IIS will put all future requests to the same page from other users in a line and all of them will be waiting until this upload...
2
by: Simon | last post by:
I have a .Net C Sharp page (aspx) serving up as a .kml file. On my localhost and an internal test server the page serves correctly and opens Google Earth. On my production server, I am served the...
9
by: ShaneFowlkes | last post by:
Hey guys... I have a form that asks for several dates. I tried using asp calendar controls to set values of the date textboxes which were readonly. I found this annoying since each time I...
12
by: Mesan | last post by:
I have a directory in an app I'm building that has access limited to users within a specific role and all aspx pages in that directory are unavailable just as I'd hope but other files (pdfs and...
2
by: Paulo | last post by:
Why when I click .asp page shows up this error on VS 2005: "This type of page is not served." Can I configure it to run .asp pages?
13
by: lawpoop | last post by:
Hello all - I have a two part question. First of all, I have a website under /home/user/www/. The index.php and all the other website pages are under /home/user/www/. For functions that are...
0
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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
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.