Browse to file and attach link instead of actual file - InfoPath Dev
in

InfoPath Dev

Browse to file and attach link instead of actual file

Last post 05-25-2010 01:13 PM by mpduval. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 05-18-2010 01:21 PM

    Browse to file and attach link instead of actual file

    Hi, I'm trying to write the code to allow users to browse to a file location on our servers and select a file, but instead of attaching that file I want just the link to be embedded.  The users have been attaching too many files to the forms and it's getting bogged down by slow load times, so I want to see if this can speed up load times on the forms.  I've put a repeating Hyperlink section on the form, and a button below it.  The code is going behind the button.

     I got the browse window to pop up easy enough and locate the file URL, but I can't seem to get the navigator to interact with the XML (these are browser-enabled forms, for putting into a MS SharePoint library, if that makes a difference).

    Here's what I have so far...

     

    Public Sub CTRL203_5_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)

    Dim openFileDialog1 As New OpenFileDialog()

    openFileDialog1.InitialDirectory = "\\Server\People\mduval"

    openFileDialog1.Filter = "All files (*.*)|*.*"

    openFileDialog1.FilterIndex = 2

    openFileDialog1.RestoreDirectory = True

     

    If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then

    Dim uri As New Uri(openFileDialog1.FileName)

    System.Diagnostics.Debug.Print(uri.OriginalString)

    Dim navigator As XPathNavigator = MainDataSource.CreateNavigator()

    Dim links As XPathNavigator = navigator.SelectSingleNode("/my:myFields/my:IWDiligences/my:IWDiligenceLinks", NamespaceManager)

    System.Diagnostics.Debug.Print(links.Name)

    Dim attach As XmlReader = XmlReader.Create(New IO.StringReader("<IWDiligenceLink>" + uri.OriginalString + "</IWDiligenceLink>"))

    links.AppendChild(attach)

    links.MoveToParent()

    System.Diagnostics.Debug.Print("Test: " + links.OuterXml)

    End If

    End Sub

     

    If this is something someone else has done, feel free to just link me to it.  I couldn't find something similar anywhere, but there's no need to repeat yourself if you've solved it for somebody else.  Also, not sure why this text just turned blue...but I'll leave it anyways.  Thanks!

     

    Edit: Also, is there a way to format this text so that it doesn't get thrown out into block quotes like that?

    Filed under: ,
  • 05-19-2010 11:06 PM In reply to

    Re: Browse to file and attach link instead of actual file

    Hi MPDuval,

    Yes, this is one of the most common requests that we solved many years ago. Qdabra's qRules v2.1 does this for files and/or images stored on SharePoint and in a SQL database (link), but seems like it doesn't support just a file server. That's silly. We'll need to look at fixing that in v2.2. Qdabra pays for this free forum and sells very cheap tools like qRules that enable commonly requested features in InfoPath that require code. qRules trial is free. Go to Qdbara dot com and download from products.

    Patrick Halstead
    Project Manager at Qdabra
  • 05-25-2010 01:13 PM In reply to

    Re: Browse to file and attach link instead of actual file

    Ok, so I got that all figured out.  Here's the VB code I used...

    Public Sub CTRL215_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)    Dim openFileDialog1 As New OpenFileDialog()

       openFileDialog1.InitialDirectory = \\Server\People\mduval"

       openFileDialog1.Filter = All files (*.*)|*.*"

       openFileDialog1.FilterIndex = 2

       openFileDialog1.RestoreDirectory = True

       If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then

             Dim uri As New Uri(openFileDialog1.FileName)

             Dim first As XPathNavigator = MainDataSource.CreateNavigator(). _

             SelectSingleNode("/my:myFields/my:CorpOverviews/my:CorpOverviewLinks/my:CorpOverviewLink", NamespaceManager)

          If first.Value Is "" Then

             MainDataSource.CreateNavigator(). _

             SelectSingleNode(
    "/my:myFields/my:CorpOverviews/my:CorpOverviewLinks/my:CorpOverviewLink", NamespaceManager). _

             SetValue(uri.OriginalString)

          Else

             Dim myNamespace As String = NamespaceManager.LookupNamespace("my")

             Using writer As XmlWriter = MainDataSource.CreateNavigator().SelectSingleNode( _

             "/my:myFields/my:CorpOverviews", NamespaceManager).AppendChild()

             writer.WriteStartElement("CorpOverviewLinks", myNamespace)

             writer.WriteElementString(
    "CorpOverviewLink", myNamespace, uri.OriginalString)

             writer.WriteEndElement()

             writer.Close()

             End Using

          End If

       End If

    End Sub

     

    My problem now is that this is a browser enabled form, and apparently browser enabled forms don't like System.Windows.Forms.  All I need is to figure out how to know when they've clicked the "OK" button in the browser, which is what that reference is.  Can I not use the windows browse dialog at all in browser based forms, or is there something I can do to get around this?

Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.