Note: Forums will be making significant UX changes to address key usability improvements surrounding search, discoverability and navigation. To learn more about these changes please visit the announcement which can be found HERE.

Answered Can I reuse SharePoint EditForm.aspx?

  • 19. května 2012 14:07
     
     

    Hi

    I would like to launch the SharePoint 2010 EditForm.aspx from a  vb.net Windows form application using the Webbrowser control or by other means if possible. I have the document library filename, its content type, Id and the rest of the EditForm.aspx url parameters. I tried it but it looks like it needs a parent SharePoint page to get this form started right. Is it possible?

    Thanks in advance

Všechny reakce

  • 19. května 2012 14:52
     
     
    Hello Raul,

    Have you tried using this as url in the webbrowser control.

    http://SP2010:portnumber/MyCustomList/EditForm.aspx?ID=2&ContentTypeId=0x0&IsDlg=1

    Please send us the screenshot or any additional information about any error.

    Thanks

    ajit

  • 21. května 2012 13:42
     
     

    Thanks Ajit for your reply

    Yeap, I am getting the script error 'window.FrameElement' is null or not an object when hitting the Save or Cancel button of the form. I know I can overcome this error if I modifiy the original EditForm.aspx with javascript or something else, but I have the restriction of using the original EdifForm.aspx.

    Can I modify it at run time in the window form (client side) to prevent this kind of error?, also the form will need to be closed after hitting  the save or cancel button,

    Thanks Again

    Raul

  • 22. května 2012 12:46
     
     

    Ok, after googling for the answer I found that having an url like http://.../EditForm.aspx?ID=2&Source=http://server/dummyPage   I can use a Webbrowser control event that close the form when reaching the dummyPage. That works when I hit the Cancel or Save buttons in the EditForm.aspx

    I have to get rid of the IsDlg=1 parameter in the url, otherwise the Source parameter will not work or will not redirect to the dummyPage throwing the script error described above

    The problem is I need the IsDlg parameter set to 0  (IsDlg=0) because without it, the EditForm.aspx will display a left layout display I do not need to show.

    Any suggestions I will appreciate.

    Thanks

  • 23. května 2012 1:57
    Moderátor
     
     Navržená odpověď

    Hi Raul43,

    To make the form closed or redirect to other pages, you may consider overriding the save/cancel click event using JavaScript, I have post a code snippet in the following thread, please refer to it for more information:
    http://social.technet.microsoft.com/Forums/en-US/sharepointworkflow/thread/7915acd4-8240-4cc2-8465-fdb8811d7529

    Thanks,
    Qiao


    Qiao Wei

    TechNet Community Support

  • 23. května 2012 21:04
     
     

    Thanks Qiao Wei

    I see you are modifying the pages at the server, a restriction I have, since my solution must be a client only one.

    I am launching the EditForm.aspx from a windows form using the webbrowser control, I just need to modify the form at running time so It will look like the Pop up dialog and it will close when hitting the close and save event.  I kind of getting it by modifying he url parameters and changing some visibility parameters at the webbrowser document complete or at the navigating event. I hope there will be an easier way

    Thanks again

  • 25. května 2012 2:23
    Moderátor
     
     

    Hi Raul43,

    The workaround in my previous post is using JavaScript code, which can be achieved from client side, you may try to add it to the original form page like adding a Content Editor Web Part to it and put the script code in the web part.

    Thanks


    Qiao Wei

    TechNet Community Support

  • 31. května 2012 15:45
     
      Obsahuje kód

    Ok, I am at a dead end,

    Here is my code, I have test it with a simple javascript function and it works, but when I try to implement the popup dialog it send me the script error "Object do not support this property or method", hope with this you understand what I am trying to do (openning a Sharepoint Editform in a pop up dialog fashion from a windows form using the webbrowser control), Thanks

        Private Sub NewProperties_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
              WebBrowser1.Navigate("http://win7x64/Shared%20Documents")
      
         End Sub
    
       
     Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
         
            If e.Url = WebBrowser1.Url Then
                Dim head As HtmlElement = WebBrowser1.Document.GetElementsByTagName("head")(0)
                Dim scriptEL As HtmlElement = WebBrowser1.Document.CreateElement("script")
                Dim element As IHTMLScriptElement = CType(scriptEL.DomElement, IHTMLScriptElement)
                Dim sb As New StringBuilder()
                sb.AppendLine("function myCallback(dialogResult, returnValue) {")
                sb.AppendLine("    alert('I am back!')")
                sb.AppendLine("}")
                sb.AppendLine("function showDialog() {")
                sb.AppendLine("  var options = {")
                sb.AppendLine("    url: 'http://win7x64/Shared%20Documents/Forms/EditForm.aspx?ID=1',")
                sb.AppendLine("    width: 700,")
                sb.AppendLine("    title: 'Test',")
                sb.AppendLine("    allowMaximize: true,")
                sb.AppendLine("    showClose: true,")
                sb.AppendLine("    dialogReturnValueCallback:myCallback")
                sb.AppendLine("  }")
                sb.AppendLine("  SP.UI.ModalDialog.showModalDialog(options);")
                sb.AppendLine("}")
                element.type = "text/javascript"
                element.text = sb.ToString
                head.AppendChild(scriptEL)
                WebBrowser1.Document.InvokeScript("showDialog")
                End If
    
        End Sub
    
    

    
    
    
    
    
    
  • 1. června 2012 13:12
     
     Odpovědět Obsahuje kód

    I finally found the solution to the error

     Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
            If e.Url = WebBrowser1.Url Then
                Dim head As HtmlElement = WebBrowser1.Document.GetElementsByTagName("head")(0)
                Dim scriptEL As HtmlElement = WebBrowser1.Document.CreateElement("script")
                Dim element As IHTMLScriptElement = CType(scriptEL.DomElement, IHTMLScriptElement)
                Dim sb As New StringBuilder()
                sb.AppendLine("function myCallback(dialogResult, returnValue) {")
                sb.AppendLine("    alert('I am back!')")
                sb.AppendLine("}")
                sb.AppendLine("ExecuteOrDelayUntilScriptLoaded(function () {")
                sb.AppendLine("  var options = {")
                sb.AppendLine("    url: 'http://win7x64/Shared%20Documents/Forms/EditForm.aspx?ID=33',")
                'sb.AppendLine("    width: 1000,")
                sb.AppendLine("    title: 'Test',")
                sb.AppendLine("    allowMaximize: true,")
                sb.AppendLine("    showMaximize: false,")
                sb.AppendLine("    showClose: false,")
                'sb.AppendLine("    autoSize: false,")
                sb.AppendLine("    dialogReturnValueCallback: myCallback")
                sb.AppendLine("  }")
                sb.AppendLine("  SP.UI.ModalDialog.showModalDialog(options);")
                sb.AppendLine("}, 'sp.js');")
                element.type = "text/javascript"
                element.text = sb.ToString
                head.AppendChild(scriptEL)
            End If
    The ExecuteOrDelayUntilScriptLoaded function did the magic.