I am writing an application in VB.net, visual studio 2005 and I want
to create a XML file to pass off to a HTTPRequest in javascript. I
have tried to pass it an xmldocument with out saving it, but the
HTTPRequest does not seem to recognize it as an XML file. Any
Suggestions?
Imports System
Imports System.Web
Imports System.Xml
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.Administration
Imports Microsoft.SharePoint.WebControls
Imports Microsoft.SharePoint.Utilities
Imports Microsoft.SharePoint.WebPartPages
Public Class Handler : Implements IHttpHandler
Dim myspweb As SPWeb
Dim myspsite As SPSite
Public Sub ProcessRequest(ByVal context As HttpContext) Implements
IHttpHandler.ProcessRequest
GetSharePointContext()
AddUserToGroup("258", "728")
GetUserGroups("258")
context.Response.ContentType = "application/xml"
context.Response.WriteFile("C:\xmlfile.xml")
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements
IHttpHandler.IsReusable
Get
Return False
End Get
End Property
Private Sub GetSharePointContext()
'If mySPWeb Is Nothing Then
mySPSite = New
SPSite(ConfigurationManager.AppSettings("SPServerU RL"))
mySPWeb = mySPSite.OpenWeb("/")
Dim users As SPUserCollection = mySPWeb.AllUsers
'End If
End Sub
Public Sub GetUserGroups(ByVal Userid)
GetSharePointContext()
Dim settings As New XmlWriterSettings()
settings.Indent = True
settings.NewLineOnAttributes = True
Using writer As XmlWriter = XmlWriter.Create("C:\xmlfile.xml",
settings)
writer.WriteStartDocument()
writer.WriteStartElement("root")
For Each MyGroup As SPGroup In mySPWeb.SiteGroups
Try
If Not MyGroup.Users.GetByID(Userid) Is Nothing
Then
writer.WriteStartElement("MemberOfGroup")
writer.WriteString(MyGroup.Name)
writer.WriteStartElement("MemberOfGroupID")
writer.WriteString(MyGroup.ID.ToString)
writer.WriteEndElement()
writer.WriteEndElement()
End If
Catch ex As Exception
writer.WriteStartElement("NonMemberOfGroup")
writer.WriteString(MyGroup.Name)
writer.WriteStartElement("NonMemberOfGroupID")
writer.WriteString(MyGroup.ID.ToString)
writer.WriteEndElement()
writer.WriteEndElement()
End Try
Next
writer.WriteEndElement()
writer.WriteEndDocument()
End Using
End Sub
Javascript
----------------------------------------------------------------------------------------------------------------
function xmlget(arg1,arg2,arg3,arg4,menu)
{
var xmlHttpObj = null;
if(window.XMLHttpRequest)
{
xmlHttpObj = new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
xmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
return
}
xmlHttpObj.onreadystatechange = function()
{
if (xmlHttpObj.readyState == 4)
{
if (xmlHttpObj.status == 200)
{
if (arg1=='GroupAddUserToGroup')
{
DisplayGroupMembers(xmlHttpObj.responseXML)
}
if (arg1=='GroupRemoveUserFromGroup')
{
DisplayGroupMembers(xmlHttpObj.responseXML)
}
}
}
}
var loginfilesdata ="AdminTry3.ashx?arg1=" + arg1 +
"&arg2=" + arg2 + "&arg3=" + arg3 + "&arg4=" + arg4
xmlHttpObj.open("GET",loginfilesdata, true);
xmlHttpObj.send('');
}