How can I delete a SharePoint sub site using SharePoint web services? - sharepoint

I am forced to use SharePoint web services. I need a web service which will let me delete the SharePoint sub site. I have tried to use DeleteWorkspace method (Meetings.asmx web service), but it is capable of only deleting the sub sites that are meeting workspaces (mine uses a custom template derived from team site). Any help would be appreciated, thanks.

Amazingly! No you can't do it.... I know! weird that it would left out. I'm sure there was a decision made somehwere about but beats me if I know why.
The only option is to deploy custom code - either an event receiver or a web service.

Unfortunately this isn't possible with the out-of-the-box web services. (They only have functionality for deletion at the site collection level.)
You would need to develop a custom web service and deploy that to your SharePoint farm.

If you upgrade to SharePoint 2013, there is a new method in the Sites web service: DeleteWeb. It expects URL of the subsite to delete, relative to the site that you connected the web service to.
--- Ferda

like Ben Says, using /_vti_bin/Dws.asmx should be works. Here's another example
public bool DeleteSubSite(string urlSubSite, string user, string passw, string domain)
{
bool retValue = true;
Dws docWS = new Dws();
docWS.Url = urlSubSite + "/_vti_bin/Dws.asmx"; ;
docWS.Credentials = new System.Net.NetworkCredential(user, passw, domain);
try
{
docWS.DeleteDws();
}
catch (SoapException soex)
{
retValue = false;
}
return retValue;
}

If you want to delete a site try using the dws webservice.
I used DWS.DeleteDWS() where the functoins get_constant etc. simple get back constants for login and webservices like _vti_bin/dws.asmx
Public Function RemoveWSSSite(ByVal sPath As String, ByVal sSubSiteName As String) As Boolean
Dim DTConstant As New DTFrameWork.DTConstant
Dim SPDWS1 As New SPDws.Dws
Dim sSubsiteURL As String = ""
If (sSubSiteName = "") Then
sSubsiteURL = ""
Else
sSubsiteURL = sSubSiteName & "/"
End If
SPDWS1.PreAuthenticate = True
SPDWS1.Credentials = New System.Net.NetworkCredential(DTconst.Get_Constant_String_Value("SP_m_AdminUser"), DTconst.Get_Constant_String_Value("SP_m_AdminPassword"), DTconst.Get_Constant_String_Value("SP_m_SiteDomain"))
SPDWS1.Url = DTconst.Get_Constant_String_Value("SP_m_SiteServerName") & IIf(sPath.StartsWith("/"), "", "/") & sPath & IIf(sPath.EndsWith("/"), "", "/") & sSubsiteURL & DTconst.Get_Constant_String_Value("SP_m_dws_asmx")
Try
SPDWS1.DeleteDws()
Return True
Catch ex As Exception
Return False
End Try
End Function

Related

DocuSign Agent/Specify Recipient role

We are using DocuSign's RESTful APIs to create and send envelopes for our clients for last few years with .net framework. We have encountered a strange issue using the Approve tab with a few of our clients' accounts. For some clients' accounts, we are able to add the Approve tab fine while we are receiving an exception while adding the Approve tab for other client accounts. Here is how we are adding the Approve tab from our codebase.
If signer.Tabs.ApproveTabs Is Nothing Then
signer.Tabs.ApproveTabs = New List(Of DocuSign.eSign.Model.Approve)
End If
Try
Dim approvatab As New DocuSign.eSign.Model.Approve
If Not currtab.anchorIgnoreIfNotPresent Is Nothing Then
approvatab.AnchorIgnoreIfNotPresent = currtab.anchorIgnoreIfNotPresent
End If
approvatab.AnchorString = currtab.anchorString
approvatab.AnchorUnits = currtab.anchorUnits
approvatab.AnchorXOffset = currtab.anchorXOffset
approvatab.AnchorYOffset = currtab.anchorYOffset
If Not currtab.bold Is Nothing Then
approvatab.Bold = currtab.bold
End If
approvatab.ButtonText = currtab.buttonText
approvatab.ConditionalParentLabel = currtab.conditionalParentLabel
approvatab.ConditionalParentValue = currtab.conditionalParentValue
approvatab.Font = currtab.font
approvatab.FontColor = currtab.fontColor
approvatab.FontSize = currtab.fontSize
approvatab.Height = currtab.height
If Not currtab.italic Is Nothing Then
approvatab.Italic = currtab.italic
End If
approvatab.PageNumber = currtab.pageNumber
approvatab.RecipientId = currtab.recipientId
approvatab.TabId = currtab.tabId
approvatab.TabLabel = currtab.tabLabel
approvatab.TabOrder = currtab.tabOrder
If Not currtab.underline Then
approvatab.Underline = currtab.underline
End If
approvatab.Width = currtab.width
approvatab.XPosition = currtab.xPosition
approvatab.YPosition = currtab.yPosition
approvatab.DocumentId = currtab.documentId
signer.Tabs.ApproveTabs.Add(approvatab)
Catch ex As Exception
Dim errmsg As String = ex.Message.ToString
End Try
The exception that we are getting while adding the Approve tab is
"Conversion from string "false" to type 'Long' is not valid"
The same code works fine for some of our clients' accounts and we are able to add the Approve tab fine.
Please advise,
Minal
Here are some recommendations:
Consider using the eSign Nuget Package. It works for VB code as well as C# code. Since it's generated from the swagger file of the DocuSign eSignature REST API it is always consistent with the latest API.
Make sure to use the v2.1 version of the eSign API and not version 2.0
Note that sometimes the API expect "false" and other times false for a Boolean value (meaning it's a string in some cases whereas it's a Boolean in the JSON in others). It's possible that there are temporary differences between customers' accounts configurations, but in the long term if you use the latest eSign API - they should behave the same.
Lastly, it could be a case of a misleading error message which hides the real issue with the account. If the issue persists I would advise to contact customer support with account numbers to try to find out.

Replace all in a specific folder

In my Test Plan I have two folders. One with all my active test cases and one with all my archived test cases. I need to replace a lot of 'Affected Module' from one value to another, however - I don't want the folder with archived to be affected by this.
So, is there a way of doing search and replace only on a specific folder (and all the sub-folders) in HP ALM?
As far as I know the search and replace function in grid view replaces all instances of the value so I can't use that directly.
Here is a simple OTA code that updates the field ts_user_04 for all the test case in folder Subject\Automated and its sub-folder from whatever value to Quoting.
Please, change the column name as per your requirement. You can easily find the DB column for any field in HP ALM by going to the Management tab if you have access to it. Even otherwise you can get all the mapping by using OTA. (I hope you have the necessary access)
Inorder to run the OTA code, you need to install ALM Connectivity add-in which you can get it from the tools section in your ALM home page
Public TDconnection
Public reqPath
Public testPath
'Call the main Function
updateAllTests
Public Function login()
Dim almURL, almUserName, almPassword, domain, project
almURL = "https://.saas.hp.com/qcbin/"
almUserName = ""
almPassword = ""
domain = ""
project = ""
testPath = "Subject\Automated" ' Change it as per your folder structure
Set TDconnection = CreateObject("tdapiole80.tdconnection")
TDconnection.ReleaseConnection
TDconnection.InitConnectionEx almURL
TDconnection.login almUserName, almPassword
TDconnection.Connect domain, project
End Function
Public Function updateAllTests()
login
Set TreeMgr = TDconnection.TreeManager
Set TestTree = TreeMgr.NodeByPath(testPath)
If Err.Number = 0 Then
Set comm = TDconnection.Command
comm.CommandText = "update test set ts_user_04='Quoting' where ts_test_id in (select ts_test_id from test, all_lists where ts_subject in (select al_item_id from all_lists where al_absolute_path like (select al_absolute_path from all_lists where al_item_id=" & TestTree.NodeID & ") || '%' ) and ts_subject = al_item_id)"
comm.Execute
End If
logout
MsgBox "Flag Update successful", vbInformation
End Function
Public Function logout()
TDconnection.Disconnect
TDconnection.logout
TDconnection.ReleaseConnection
Set TDconnection = Nothing
End Function

Sharepoint Alerts on List Folders

I would like to programatically add alert to folders inside a sharepoint list. I have found how to set alerts to a list and this works perfect.
Could someone please help me on how to set alerts to a specific folder which is inside a list.
Below is the code i currently have which sets alerts only to the list.
using (SPSite site = new SPSite("http://site/"))
{
using (SPWeb web = site.OpenWeb())
{
SPUser user = web.SiteUsers["domain\\user"];
SPAlert newAlert = user.Alerts.Add();
newAlert.AlertType = SPAlertType.List;
newAlert.List = web.Lists["Documents"];
newAlert.EventType = SPEventType.All;
newAlert.AlertFrequency = SPAlertFrequency.Immediate;
//passing true to Update method will send alert confirmation mail
newAlert.Update(true);
}
}
Your help will be much appreciated
THIS QUESTION IS RESOLVED! PLEASE SEE MY POST BELOW WITH THE LINK - SEE - LINK
That's not possible out of the box, but after googling I found an interesting possibility though, check out Mike Walsh's answer on this post, it entails creating a view in the folder and then attaching the alert to that view.
You need to update the line with
newAlert.List = web.Lists["Documents"];
With
SPFolder fldr = web.GetFolder("/ListName/FolderName");
newAlert.Item=fldr.Item;
Also note that Folder is also another item.

SharePoint document library versioning and require check out settings using web services

I need the information about the SharePoint document library. Namely, I need the info whether the versioning is turned on or off and if the "require check out" option is selected. I have to use SharePoint web services.
I have looked up in Versions.asmx, Lists.asmx and SiteData.asmx, but found no method or properties that suit my needs.
Could anyone help me out please? Thanks.
You will need to make use of the lists.asmx GetList method. It returns all of the metadata about a list.
Here's some code I've been using in combination with Linq to XML:
Private _serviceRefrence As SharePointListsService.ListsSoapClient
Dim endPoint As New ServiceModel.EndpointAddress(_serviceURL)
Dim ListID as Guid = New Guid("<<Your List Guid>>")
_serviceRefrence = New SharePointListsService.ListsSoapClient("ListsSoap", endPoint)
_serviceRefrence.ClientCredentials.Windows.ClientCredential = Credentials
_serviceRefrence.ClientCredentials.Windows.AllowedImpersonationLevel = Security.Principal.TokenImpersonationLevel.Impersonation
Dim results As XmlElement = _serviceRefrence.GetList(listID.ToString())
Dim parserResults As XDocument = XDocument.Parse(results.OuterXml)
Dim listinfo = (From list In parserResults.Descendants(XName.Get("List", "http://schemas.microsoft.com/sharepoint/soap/")) _
Select New With {.RequireCheckout = list.Attribute("RequireCheckout").Value, _
.ModerationEnabled = list.Attribute("EnableModeration").Value, _
.VersioningEnabled = list.Attribute("EnableVersioning")}).Single()
Hope this helps!

MOSS SpNavigationNode.Children always empty

I'm trying to return all the child nodes of a set of navigation nodes in sharepoint, the SDK implies I should be doing something like this:
NodeColl = objSite.Navigation.TopNavigationBar
Dim Node as SPNavigationNode
For Each Node In NodeColl
if Node.IsVisible then
Response.Write("<siteMapNode url=""" & Node.Url & """ title=""" & Node.Title & """ description=""" & Node.Title & """ >" & Environment.NewLine)
Dim SubChildNodes as SPNavigationNodeCollection = Node.Children
Response.Write(SubChildNodes.Count) 'returns 0 always even though I know theres over 20 nodes in some of the sections
Dim ChildNode as SPNavigationNode
For Each ChildNode in SubChildNodes
if ChildNode.IsVisible then
Response.Write("<siteMapNode url=""" & ChildNode.Url & """ title=""" & ChildNode.Title & """ description=""" & ChildNode.Title & """ />" & Environment.NewLine)
End if
Next
Response.Write("</siteMapNode>" & Environment.NewLine)
End If
Next
however whenever I do, it lists the top level navigation nodes but I cannot get the children to be displayed.
I was facing the same issue: I was trying to access the SPWeb.Navigation.Quicklaunch from a web-scoped feature's feature receiver activated from onet.xml, but the SPWeb.Navigation.QuickLaunch.Count was always 0, even though I had definitely added list instances in other features activated previously in the same onet.xml.
The solution for me was to open a new SPSite and a new SPWeb in my feature receiver, after which I was able to access the quick launch items. For example this worked for me:
using (SPSite site = new SPSite("http://yourserver/"))
{
using (SPweb web = site.OpenWeb("theweb"))
{
web.Navigation.QuickLaunch.Count ; // greater than zero
// manipulate your quick launch here
}
}
I'm assuming this is because creating the new SPWeb object loads the web's most recent state from database, and the SPWeb passed to my feature receiver didn't represent the latest state. But this is me gues
I have this same problem, I found the solution as
using (SPSite site = new SPSite("http://server"))
{
using (SPWeb web = site.OpenWeb())
{
SPNavigationNode quicklaunch = web.Navigation.GetNodeById(1025);
if (quicklaunch != null)
{
foreach (SPNavigationNode heading in quicklaunch.Children)
{
PrintNode(heading);
}
}
}
}
static void PrintNode(SPNavigationNode node)
{
foreach (SPNavigationNode item in node.Children)
PrintNode(item);
}
Make sure you have a SiteMapDataSource associated with your master page quick launch.

Resources