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

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!

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.

How to get CustomDocumentProperties using Excel Interop (VB.net)?

I have an Excel document that is created using Excel Interop written in VB.net. Adapting information from this post, I am able to successfully create a workbook and write its CustomDocumentProperties using:
Dim objNewApp As Excel.Application
Dim objNewBook As Excel._Workbook
Dim objNewBooks As Excel.Workbooks
objNewApp = New Excel.Application With {
.DisplayAlerts = True,
.Visible = True,
.UserControl = True,
.ScreenUpdating = True
}
objNewBooks = objNewApp.Workbooks
objNewBook = objNewBooks.Add
Dim properties As Object = objNewBook.CustomDocumentProperties
Dim propertiesType As Type = properties.[GetType]()
Dim documentClient As Object() = {"Client", False, Core.MsoDocProperties.msoPropertyTypeString, "In-Progress"}
propertiesType.InvokeMember("Add", BindingFlags.InvokeMethod, Nothing, properties, documentClient)
However, I have not been able to successfully read this property after it is set. After doing a thorough search, most posts on the topic here on SO, as well as MSDN, suggest reading this missing MSDN article to learn more about how to do this, noting how goofy it is to do in Interop in general. However, I am using Interop for the rest of my program, so I would like to find an Interop-specific solution (instead of VSTO).
Adapting from this post, I believe my current code is on the right track:
Dim ReadClient As String = "Client"
Dim ObjReadClient = propertiesType.InvokeMember("Item", BindingFlags.GetProperty, Nothing, properties, New Object() {ReadClient})
Dim TypeReadClient As Type = ObjReadClient.GetType
Dim ClientString As String
ClientString = TypeReadClient.InvokeMember("Value", BindingFlags.GetProperty, Nothing, properties, New Object() {})
However, when I run this I receive an System.Runtime.InteropServices.COMException:
"Unknown name. (Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))"
Doing more research, this appears to be due to the "Value" piece on the last line of code. I was unable to figure out where to go from there.
Does anyone have any idea as to this last piece of the puzzle? I'd be happy to clarify anything if needed!
Here is the solution for my particular problem:
Dim ReadClientIndex As String = "Client"
Dim ReadClientValue As String
Dim ObjReadClient As Object = propertiesType.InvokeMember("Item", BindingFlags.GetProperty, Nothing, properties, New Object() {ReadClientIndex})
Dim TypeReadClient As Type = ObjReadClient.GetType()
ReadClientValue = TypeReadClient.InvokeMember("Value", BindingFlags.GetProperty, Nothing, ObjReadClient, New Object() {})
Apart from cleaning up the code, the issue was that I should have referred to "ObjReadClient" as the argument in the last line - not the "properties" variable set earlier.
However, since there is a notable lack of documentation on this topic in VB.net or C#, here are some resources that might help future users:
Link 1: Provided code originally in the missing MSKB article (in C#, copied again below for preservation.):
Word.Application oWord;
Word._Document oDoc;
object oMissing = Missing.Value;
object oDocBuiltInProps;
object oDocCustomProps;
//Create an instance of Microsoft Word and make it visible.
oWord = new Word.Application();
oWord.Visible = true;
//Create a new Document and get the BuiltInDocumentProperties collection.
oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing,
ref oMissing);
oDocBuiltInProps = oDoc.BuiltInDocumentProperties;
Type typeDocBuiltInProps = oDocBuiltInProps.GetType();
//Get the Author property and display it.
string strIndex = "Author";
string strValue;
object oDocAuthorProp = typeDocBuiltInProps.InvokeMember("Item",
BindingFlags.Default |
BindingFlags.GetProperty,
null,oDocBuiltInProps,
new object[] {strIndex} );
Type typeDocAuthorProp = oDocAuthorProp.GetType();
strValue = typeDocAuthorProp.InvokeMember("Value",
BindingFlags.Default |
BindingFlags.GetProperty,
null,oDocAuthorProp,
new object[] {} ).ToString();
MessageBox.Show( "The Author is: " + strValue,"Author" );
//Set the Subject property.
strIndex = "Subject";
strValue = "The Subject";
typeDocAuthorProp.InvokeMember("Item",
BindingFlags.Default |
BindingFlags.SetProperty,
null,oDocBuiltInProps,
new object[] {strIndex,strValue} );
//Add a property/value pair to the CustomDocumentProperties collection.
oDocCustomProps = oDoc.CustomDocumentProperties;
Type typeDocCustomProps = oDocCustomProps.GetType();
strIndex = "Knowledge Base Article";
strValue = "Q303296";
object[] oArgs = {strIndex,false,
MsoDocProperties.msoPropertyTypeString,
strValue};
typeDocCustomProps.InvokeMember("Add",BindingFlags.Default |
BindingFlags.InvokeMethod, null,
oDocCustomProps, oArgs );
MessageBox.Show("Select \"Properties\" from the File menu "
+ "to view the changes.\nSelect the Summary tab to view "
+ "the Subject property and the Custom tab to view the Knowledge"
+ "Base Article property.", "Check File Properties",
MessageBoxButtons.OK,MessageBoxIcon.Information);
Link 2: Notes that it is easier to accomplish in VB.net, but that C# will soon support late-binding using "Dynamic" (written 10 years ago). I found another post somewhere that explained the importance of "Dynamic" as an answer in C#, but was unable to find it again to link to.
Link 3: This information is specific to Excel, but I believe it may help someone looking for it specifically.
Link 4: This gives an example mistaking VTSO and Interop, which may help users differentiate between the two.
To get custom properties using c# is bit a different approach. Pls check these 2.
Not copying whole code for dedup.
How can I read excel custom document property using c# excel interop
How to get CustomDocumentProperties using Excel Interop?

SharePoint 2010: How do I connect FilterWebPart with ReportViewWebPart

I have the requirement to add performance point filter web part and report view web part to a page in SharePoint 2010 programmatically. I can add both web parts to the page however I have no idea on how to setup connection between them, i.e. for filter web part to be able to send its value to the report view web part.
Any help would be much appreciated.
Found the solution to this :)
What I did was when I create the connection using SPConnectWebParts, I use TransformableBIDataProviderTransformer object, e.g.
var list = new List<TransformProviderConsumerRecord>();
var transformer = new TransformableBIDataProviderTransformer();
var tpcRecord = new TransformProviderConsumerRecord();
tpcRecord = "SqlReportViewUniqueParameterIdSI1";
tpcRecord.ProviderParameterName = "FilterValues";
tpcRecord.DisplayColumnName = "DisplayValue";
tpcRecord.MappingId = (new Guid()).ToString();
tpcRecord.ProviderParameterDisplayName = "PerformancePoint Values";
tpcRecord.TypeFullName = "System.String";
tpcRecord.ValuesColumnName = "DisplayValue";
list.Add(transformProvConsRecord);
ProviderConsumerTransformations provConsTransf = new ProviderConsumerTransformations(list);
var tcr = new TransformerConfigurationRecord(provConsTransf, new TransformConditionalVisibilityRecord());
transformer.ConfigurationState = tcr;
wpm.SPConnectWebParts(providerWp, providerConnection, consumerWp, consumerConnection, transformer);
Where providerWP is Performance Point filter web part amd consumerWp is Performance Point Report

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.

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

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

Resources