|
I want to load an xml file into my program then extract data from it into text boxes. For loading purpose I would like to be able to have something that looks like the open file dialog. So that I can select different xml file each time load it into my program have it take the layout I would like be able to alter any text then save the alteration and print it out.
|
|
|
|
|
Are you using VB or VB.Net?
VB.Net:
Use an OpenFileDialog, use System.Xml.Linq.XDocument.Load(filePath) to get an XDocument and then recursively get every node. If it has child nodes, recurse further. If not, write the child node text somewhere. To save it, just save the XDocument, and have any editing alter the XDocument itself
So, in summary
Load:
OpenFileDialog. Get filename
System.Xml.Linq.XDocument.Load(FileName)
Get every node
If node has child node: go to previous instruction
Else: write node details
Editing node:
Alter XDocument itself
Saving:
XDocument.Save
VB[1-6]:
Interface with COM. I can't help you here
modified on Thursday, April 16, 2009 6:50 AM [Needed to clarify]
|
|
|
|
|
i am using visual studio 2008 express edition vb
thanks for the info i will have to try that
|
|
|
|
|
Is XDocument a DOM implimentation ? What does it offer over the non LINQ DOM class ?
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
Probably not much that actually matters, but LINQ exposes the xml document's structure and tags to Visual Studio's intellisense. In other words, it makes writing code for a specific xml structure easier for he developer.
My advice is free, and you may get what you paid for.
|
|
|
|
|
Not really that much in all honesty, but it makes XML a lot easier. It works with LINQ far more easily, which is useful if he ever wants to apply the principles to other projects. I'm not certain, but going by this link, it doesn't the XDocument class doesn't appear to be DOM (to be precise, the Remarks and Examples sections imply this). Also, an XElement doesn't require creation from an XDocument, which doesn't tie it down to one particular XML file
|
|
|
|
|
ok here is my code for loading the file
<pre>Imports System.Xml.XPath
Imports System.Xml.Linq
Imports System
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim xmldoc As XDocument = XDocument.Load("OpenFileDialog1.FileName")
Dim
OpenFileDialog1.Filter = "Xml (*.xml)|*.xml"
OpenFileDialog1.ShowDialog()
System.Xml.Linq.XDocument.Load(OpenFileDialog1.FileName)
End Sub
End Class </pre>
How do i load node text into text box from here
a simple xml file for testing here person.xml
<pre>
<xml version="1.0" encoding= "utf=8"?>
<Person>
<FName>Keith</FName>
<LName>Ryan</LName>
</Person>
</pre>
thanks
|
|
|
|
|
I have searched for answers on the web, have some good suggestions but they do not seem to fix my problem.
On a web form, I have a report with a sub-report. No matter what I do, I get the error message "Error: Subreport could not be shown."
I can run the subreport as a main report on another page, and it works fine.
I found elsewhere that I have to add a handler for the subreportpreocessing event, and have done so but it does not get called when I step through the code.
Below is some code for the events that lead up to the problem:
==========
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim JobAppID As Integer = Val(Me.DDL_JobAppID.SelectedValue) 'For main report parameter
Dim params(0) As ReportParameter
Me.ReportViewer1.LocalReport.ReportPath = ".\admin\employmentapplicant.rdlc"
AddHandler ReportViewer1.LocalReport.SubreportProcessing, AddressOf SubreportDatabind
params(0) = New ReportParameter("vJobAppID", JobAppID, False)
Me.ReportViewer1.LocalReport.SetParameters(params)
Me.ReportViewer1.LocalReport.Refresh()
'End If
End Sub
Public Sub SubreportDatabind(ByVal sender As Object, ByVal e As SubreportProcessingEventArgs)
Dim MyReportDataSource = New ReportDataSource("DS_References", Me.DS_References)
e.DataSources.Add(MyReportDataSource)
End Sub
==
Also, in the .aspx file I have tried both with and without the following:<LocalReport ReportPath="Admin\EmploymentApplicant.rdlc" OnSubreportProcessing="SubreportDatabind">
Help would be appreciated!!
Dave McDonald
Web Developer
|
|
|
|
|
Well, I haven't used ReportViewer and don't do ASP.NET apps, so my experience is quite limited.
But, from what I can see, everything looks OK. The only question I have is what does the code look like that defines and sets up "MyReportDataSource"? Is this the same source used for the parent report??
|
|
|
|
|
I've got a project that requires merging of several PDF documents into one PDF document. From my research, it is my understanding that this cannot be done without a third party component or library.
Our current plan is to run the merge on a web service call, however we are interested in exploring the costs of using the component in a PC program deployed to our users. It needs to work for .Net 2.0 or higher.
Does anyone have any recommendations for a good one? And/or one that isn't too costly?
|
|
|
|
|
I too would be interest in an answers, as I have a similar requirement, but does not need to a windows or web service.
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
You are correct that there is no built-in support for this in .NET.
There are several free libraries that support interaction with PDF files, so you could utilise one of those to write your own merge component. Very very steep learning curve though (Googling 'PDF Files .NET' got hits for all the ones I was aware of, and others).
At the end of the day I suppose it is a cost comparison between doing that and whatever paid-for component you eventually decide on.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi everybody,
i got a problem. i'm developping an vb.net application. now i want to load a word file into a richtextbox with all the formatting text from word.
Or
how can i load the whole word file into a control in vb.net that can support it?
Thanks for your help.
Marc.
|
|
|
|
|
Try loading an RTF file. That has most of the formatting available in Word, and can be opened by Word, Wordpad, and the RichTextBox control
|
|
|
|
|
marclenoir2005 wrote: now i want to load a word file into a richtextbox with all the formatting text from word.
Generally speaking, not possible. The RichTextBox doesn't support the Word file format. You'd have to save the document in RTF format, then load that version into the RichTextBox. Now, there's another problem. The RichTextBox doesn't support the entire RTF specification. Meaning, while Word will save all the formatting and other goodies in RTF format, the RichTextBox doesn't understand it all and will not render the document properly if the document contains formatting it doesn't support.
|
|
|
|
|
Dave Kreskowiak wrote: The RichTextBox doesn't support the entire RTF specification
That could be a problem. Is there a list anywhere which has more information about this? Some of my coursework uses this setup for convenience, and it's saved using Word, so this could be a possible problem
|
|
|
|
|
Hi,
I don't know any details except this one: I have successfully been creating RTF files programmatically containing tables, which Wordpad can display but not create or drastically edit. And AFAIK Wordpad and the RichTextBox are based on the same basic control.
IMO a WebBrowser can show (not edit) a Word document, just like Internet Explorer can.
|
|
|
|
|
Luc 648011 wrote: IMO a WebBrowser can show (not edit) a Word document, just like Internet Explorer can.
So long as either Word or Word Viewer is installed, this is true. If not, IE can't display the document and you'll get a Save File option for the .DOC file.
|
|
|
|
|
thanks for your help.
I think it is not possible to do this like I want.
Thank you everybody.
|
|
|
|
|
You're very welcome. Always glad to help
|
|
|
|
|
Hey,
Don't give up hope yet, maybe this[^] can help you
Zaegra
Motivation is the key to software development.
|
|
|
|
|
This is really frustrating. I produced some graphs using GDI and vb.net and on the screen they look fine. When you print them off on a black and white printer they look fine BUT on a colour printer the quality is really bad. you can see lines in the colours which is just not acceptable..
I have included the sample code below. I have tried changing to bmp, png etc and it makes not difference.. what am I missing ?.. i can send a copy of the picture produced if anyone can help or you can just copy the code and try running it..
Thanks
Peter
----- Default.aspx
]]>
<title>Untitled Page
----- Default.aspx.vb
Imports System.Configuration
Imports System.Drawing.Printing
Imports System.Drawing
Imports System.Drawing.Imaging
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim brshObj As SolidBrush = New SolidBrush(Color.White)
Dim new_font As New Font("Tahoma", 6)
Dim x, y, i As Integer
Dim MTmonths(12) As String
Dim iloop, rec, lastx, lasty1, lasty2 As Integer
Dim starty, endy, ydiv, stepdiv, yaxis As Double
Dim j
Dim allMonths As String = "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec"
Dim monthNames(12) As String
monthNames = Split(allMonths, ",")
Dim LY_Yield(12) As Double
Dim TY_Yield(12) As Double
Dim TYield As String = "20.42,18,15.6,17.22,17.31,19.14,16.52,18.25,18.52,0,0,0"
Dim LYield As String = "22.16,20.59,16.72,17.3,18.35,18.24,19.24,19.62,17.62,16.56,14.53,16.08"
Dim sTYield(13) As String
Dim sLYield(13) As String
sTYield = Split(TYield, ",")
sLYield = Split(LYield, ",")
For rec = 1 To 12
LY_Yield(rec) = CDbl(sLYield(rec - 1))
TY_Yield(rec) = CDbl(sTYield(rec - 1))
MTmonths(rec) = monthNames(rec - 1)
Next
Dim maxy As Double
Dim miny As Double
Dim m1, m2 As Double
maxy = -9999999
miny = 9999999
For iloop = 1 To 12
m1 = TY_Yield(iloop) : m2 = LY_Yield(iloop)
If m1 <> -9999 And m1 <> 0 Then
If m1 > maxy Then maxy = m1
If m1 < miny Then miny = m1
End If
If m2 <> -9999 And m2 <> 0 Then
If m2 > maxy Then maxy = m2
If m2 < miny Then miny = m2
End If
Next
Dim objBitmap As Bitmap = New Bitmap(340, 230)
Dim objGraphics As Graphics = Graphics.FromImage(objBitmap)
Dim bmpNew As Bitmap = New Bitmap(objBitmap.Width, objBitmap.Height)
'bmpNew.SetResolution(280, 220)
Dim oGraphic As Graphics = Graphics.FromImage(bmpNew)
Dim rectObjB As Rectangle = New Rectangle(-50, -50, objBitmap.Width + 50, objBitmap.Height + 50)
Dim rectObj As Rectangle = New Rectangle(0, 0, objBitmap.Width, objBitmap.Height)
oGraphic.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
oGraphic.FillRectangle(brshObj, rectObj)
Dim pn1 As Pen = New Pen(Color.Red, 1)
Dim pn2 As Pen = New Pen(Color.RoyalBlue, 3)
Dim pnax As Pen = New Pen(Color.Black, 2)
oGraphic.DrawLine(pnax, 20, 210, 340, 210)
oGraphic.DrawLine(pnax, 20, 210, 20, 20)
objBitmap.RotateFlip(RotateFlipType.RotateNoneFlipY)
Dim TextBrsh As Brush = New SolidBrush(Color.Black)
Dim TextFont As New Font("Arial", 8, FontStyle.Regular)
For i = 1 To 12
x = ((i / 12) * 300) - 5
oGraphic.TextRenderingHint = Text.TextRenderingHint.AntiAliasGridFit
oGraphic.DrawString(MTmonths(i), TextFont, TextBrsh, x, 210)
Next
Dim aPoints(11) As Point
Dim bPoints(11) As Point
endy = maxy + (maxy * 20 / 100) : starty = miny - (miny * 20 / 100) : endy = Math.Floor(endy + 0.5) : starty = Math.Floor(starty + 0.5) : stepdiv = Math.Round((endy - starty) / 8, 0)
ydiv = endy - starty
For yaxis = starty To endy Step stepdiv
y = (-1 * ((yaxis - endy) / ydiv * 190))
oGraphic.DrawLine(Pens.Gray, 20, y + 20, 340, y + 20)
oGraphic.TextRenderingHint = Text.TextRenderingHint.AntiAliasGridFit
oGraphic.DrawString(yaxis, TextFont, TextBrsh, 1, y + 10)
Next
i = 1 : j = endy : lastx = 20 : lasty1 = 200 : lasty2 = 200
For iloop = 1 To 12
x = (i / 12) * 300
j = LY_Yield(iloop)
If j <> -9999 Then
y = (-1 * ((j - endy) / ydiv * 190))
Else
y = lasty1
x = lastx
End If
aPoints(i - 1).X = x : aPoints(i - 1).Y = y
lasty1 = y
j = TY_Yield(iloop)
If j <> -9999 Then
y = (-1 * ((j - endy) / ydiv * 190))
Else
y = lasty2
x = lastx
End If
bPoints(i - 1).X = x : bPoints(i - 1).Y = y
lasty2 = y
i = i + 1
lastx = x
Next
oGraphic.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
' new compression technique
Dim Codec, JPEGCodec As System.Drawing.Imaging.ImageCodecInfo
Dim EncParams As System.Drawing.Imaging.EncoderParameters
Dim QualitySetting As Long = 100L
For Each Codec In System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders
If Codec.MimeType = "image/jpeg" Then
JPEGCodec = Codec
Exit For
End If
Next
EncParams = New System.Drawing.Imaging.EncoderParameters(1)
EncParams.Param(0) = New System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, QualitySetting)
'MyImage.Save(ImageFileName, JPEGCodec, EncParams)
'Dim offset As Integer = 1
'Dim segments As Integer = 3
'Dim tension As Single = 0.5F
'oGraphic.DrawCurve(pn1, aPoints, offset, segments, tension)
'oGraphic.DrawCurve(pn2, bPoints, offset, segments, tension)
oGraphic.DrawCurve(pn1, aPoints, 0.5F)
oGraphic.DrawCurve(pn2, bPoints, 0.5F)
objBitmap = bmpNew
objBitmap.Save(Server.MapPath("~/GT1.jpg"), ImageFormat.Jpeg)
objBitmap.Save(Server.MapPath("~/GT2.jpg"), JPEGCodec, EncParams)
objBitmap.Dispose()
End Sub
End Class
|
|
|
|
|
Since you're not doing any printing from your code, the result is going to be up to the printer driver and it's configuration on the client machine.
You're also going to have to show a picture of the result. You can post a link to a pic uploaded to ImageShack or Flickr or any other image hosting service.
Frome what you're describing, it doesn't look like you've got much in the way of options that you have control over.
|
|
|
|
|
thanks for that... are you saying the code looks fine ?
you can find the image at
http://www.flickr.com/photos/31889627@N08/3444828205/
cheers
Peter
|
|
|
|
|
That looks fine to me, except for the text, which is very low-res, but then you have chosen to use only a small bitmap in Bitmap(340, 230)
Images tend to scale rather well, for text having its rendering delayed as much as possible is advantageous, since in the end it is the printer that knows its actual resolution, the available fonts, etc. Rendering the text early on and in a (small) bitmap isn't good for final quality.
|
|
|
|
|