wordpress hit counter
OpenXML Developer
Goodbye and Hello

OpenXmlDeveloper.org is Shutting Down

There is a time for all good things to come to an end, and the time has come to shut down OpenXmlDeveloper.org.

Screen-casts and blog posts: Content on OpenXmlDeveloper.org will be moving to EricWhite.com.

Forums: We are moving the forums to EricWhite.com and StackOverflow.com. Please do not post in the forums on OpenXmlDeveloper.org. Instead, please post in the forums at EricWhite.com or at StackOverflow.com.

Please see this blog post for more information about my plans moving forward.  Cheers, Eric

DocumentBuilder dont find file create in runtime

  • rated by 0 users
  • This post has 2 Replies |
  • 1 Follower
  • i use DocumentBuilder.BuildDocument(Sources, Outfile) , i created a dynamically files list (The source), i try to do a file merging this list, inside the list, i have three files, created in runtime, when i do the debug of the project, the files are there i can see him and read, but when documentbuilder take the list to do the merge, seems dont find this files, the other files (created non in runtime) are reading by the process.


    this is my code. 

     'Procedure with OpenXml - File generated with openxml
    Dim AddressFile1 As String = doc.GeneraFile1()
    Dim AddressFile2 As String = doc.GeneraFile2()
    Dim AddressFile3 As String = doc.GeneraFile3()
                Dim sources As List(Of OpenXmlPowerTools.Source) = Nothing
                sources = New List(Of OpenXmlPowerTools.Source)
                Dim MyBoolean As Boolean = True
                Dim Stringa As String = "SELECT *  FROM ListFiles"
                Dt = csDati.BaseQueryGral(Stringa)
                sources.Add(New OpenXmlPowerTools.Source(New WmlDocument(AddressFile1), MyBoolean))
                sources.Add(New OpenXmlPowerTools.Source(New WmlDocument(AddressFile2), MyBoolean))
                If Dt.Rows.Count > 0 Then
                    For Each row As DataRow In Dt.Rows
                        FileName = row("strIndFileDescrittivo").ToString()
                        StrIndirizzoDb = (Server.MapPath(FileName))
                        sources.Add(New OpenXmlPowerTools.Source(New WmlDocument(StrIndirizzoDb), MyBoolean))
                        MyBoolean = False
                End If
                sources.Add(New OpenXmlPowerTools.Source(New WmlDocument(AddressFile3), MyBoolean))
                Dim IndFinal As String = "d:\OutFinal.docx"
                DocumentBuilder.BuildDocument(sources, IndFinal)


    Any Idea about this??


    Thanks in advance

  • Hi, I'm not clear, what do you mean when you say it doesn't find the file? What is the error message?

    Cheers, Eric

  • Thanks for answer, I want to say. With three procedures, i do, three differents files, after, i combine these files just created with other files already existing in the server, but when I do this, the procedure "DocumentBuilder.BuildDocument", combine the files already existing in the server, but the three files, created before the execution of the procedure seems dont exist, and comes this error: "empty list error ". I see the files in the server, i can open the file and modify without problem.

    I hope to be clear, I post the code for the generation of one file

    Public Function GeneraFileArticoli(ByVal IdOffer As String, ByVal nomeCartella As String) As String

           Dim IndFileArticoli As String = ""


               Dim nomeDir As String = ConfigurationManager.AppSettings("DirServer")

               Dim TemplatePath As String = nomeDir + "\OpenXmlContent\ModelloGrid.docx"

               Dim OutputPath As String = nomeDir + "\" + nomeCartella + "\" + IdOffer + "-Articoli.docx"

               File.Copy(TemplatePath, OutputPath)

               Dim db As New DBOfferteDataContext

               Dim varOfferta = From prod In db.spDoc(IdOffer)

               Using theDoc As WordprocessingDocument = WordprocessingDocument.Open(OutputPath, True)

                   Dim body As Body = theDoc.MainDocumentPart.Document.Body

                   '***************************************** TABELLA CON DATI **************************************

                   Dim mainPart As MainDocumentPart = theDoc.MainDocumentPart

                   Dim ccWithTable As SdtBlock = mainPart.Document.Body.Descendants(Of SdtBlock)().Where(Function(e) e.SdtProperties.GetFirstChild(Of Tag)().Val = "ElencoProdotti").[Single]()

                   Dim theTable = ccWithTable.Descendants(Of Table)().Single()

                   Dim theRow = theTable.Elements(Of TableRow)().Last()

                   For Each articolo In varOfferta

                       Dim rowCopy As TableRow = DirectCast(theRow.CloneNode(True), TableRow)

                       rowCopy.Descendants(Of TableCell)().ElementAt(0).Append(New Paragraph(New Run(New Text(articolo.Kit.ToString()))))

                       rowCopy.Descendants(Of TableCell)().ElementAt(1).Append(New Paragraph(New Run(New Text(articolo.Codice.ToString()))))

                       rowCopy.Descendants(Of TableCell)().ElementAt(2).Append(New Paragraph(New Run(New Text(articolo.Prodotto.ToString()))))

                       rowCopy.Descendants(Of TableCell)().ElementAt(3).Append(New Paragraph(New Run(New Text(articolo.Incluso.ToString()))))

                       rowCopy.Descendants(Of TableCell)().ElementAt(4).Append(New Paragraph(New Run(New Text(articolo.Prezzo.ToString()))))





                   IndFileArticoli = docOutputPath

               End Using

           Catch ex As Exception

               Dim Problema As String = ex.Message

           End Try

           Return IndFileArticoli

       End Function

    Thank's in advance


Page 1 of 1 (3 items)