Sharepoint webservice rename a folder - c#

I am trying to use sharepoint webservice to rename a folder. I tried the below code to create a folder which works fine. But I am unable to find the webmethod related to renaming folder. Any help would be highly appreciated.
Web Service used
http://myservicelink:100/_vti_bin/Dws.asmx
Dws objDws = new Dws();
objDws.Credentials = System.Net.CredentialCache.DefaultCredentials;
string strResult = objDws.CreateFolder("MyMainFolders/MyFolder");
Console.WriteLine(strResult);
Console.ReadLine();

AFAIK there is no way to do it with web services API. But do you really have reasons to use the deprecated web-services API? (one I may think of is, you need to support SharePoint 2007 and below).
The better SharePoint API is called Share Point Client Object Model (CSOM). Here is a blog article explaining basic folder operations:
Manage (Create/Delete/Rename) list folders with SP Client Object Model

Related

Downloading from Sharepoint Document Library

Goal: Download documents from a Sharepoint 2010 Document Library using C#
I've searched and found many questions/resources regarding how to download documents to a local disk from a Sharepoint Document Library. I've so far been unable to successfully implement a solution.
For the sake of discussion, my document library is located at the following link:
http://server.domain.com/sites/CompanyLocation/dprtmnts/DepartmentName/MyLibraryName/Forms/AllItems.aspx
Within this document library are two folders, each containing a number of documents. I desire to retrieve a list of these documents (in each folder) and have the ability to download/open a document on command.
Things I've tried:
The linked post from this comment: https://sharepoint.stackexchange.com/a/105923
The linked post (https://stackoverflow.com/a/21056425/2480558) offers a solution for both downloading and uploading. I only need to download, so I tried that. This solution gives me a Microsoft.SharePoint.Client.ServerObjectNullReferenceException. There are no instructions on what the url, listTitle, or listItemId need to be, so I'm probably doing something wrong... it doesn't appear to be getting any files.
I also tried the first blog post on that answer that points to using a package from bendsoft. Apparently that package is a paid package, and it's quite expensive.. I can't go that route.
Another answer: https://stackoverflow.com/a/53733630/2480558
This gives me the following exception: (actual server edited out of exception)
Microsoft.SharePoint.Client.ClientRequestException: 'The IDCRL response header from server 'http://server.domain.com/' is not valid. The response header value is 'NTLM'. The response status code is 'Unauthorized'.
This solution: https://stackoverflow.com/a/15602003/2480558
Honestly, I don't even remember why that one didn't work.
If anyone has something that might help me get on the right path... I'm not familiar with making web requests and web authorization, or anything of that nature.
If you use the example that you found at https://stackoverflow.com/a/53733630/2480558, but you have to adapt it for your local SharePoint server, since that code is logging in to SharePoint Online.
In the public void Connect() definition, replace the line
clientContext.Credentials = new SharePointOnlineCredentials(UserName, securePassword);
with this instead:
clientContext.Credentials = new NetworkCredential(UserName, securePassword, "putYourADDomainNameHere");

Create an Azure Web App Using C#

Hi I'm currently refreshing my knowledge in C# programming.
I wanted to translate the manual way of creating a Web App in Microsoft Azure (Classic) into the C# language.
(Manual way - New > Compute > Web App > Custom Create > ...etc.. )
Whenever I search through google about this topic all it gives me is to literally create a "WebApp" in Visual Studio. (File > New > ...etc...) However, what I am looking for is how to create an Azure Web App programatically via C# - how to interact with the Management UI of the Classic Azure Portal to create a web app.
Anyone familiar to do this? Thanks in advance for the help! :)
To create an azure website easily using C#, you can use "Windows Azure Management Libraries". This SDK is a wrapper arround "Azure Service Management" API.
Here is a introduction from Braddy Gaster an a blog post, to get credentials from an Azure Tenant an work with ASM Api.
Then you will be able to create a website with something like this :
using (var AwsManagement = new Microsoft.WindowsAzure.Management.WebSites.WebSiteManagementClient(azureCredentials))
{
WebSiteCreateParameters parameters = new WebSiteCreateParameters()
{
Name = "myAws",
// this Service Plan must be created before
ServerFarm = "myServiceplan",
};
await AwsManagement.WebSites.CreateAsync("myWebSpace", parameters, CancellationToken.None);
}
I was able to work on the available code Microsoft posted in GitHub:
https://github.com/Azure/azure-sdk-for-net
I re-coded some and just acquired the functions that I only need for my program to work. :)
You can create a web site by using a POST request that includes the name of the web site and other information in the request body. You can check the code example for ASM here.

C# Check SharePoint List permissions using SharePoint Client Object Model

From a client application, I need to check if a given user has permissions on a given document library using Client object Model.
I want something equivalent of the following Server object function
spList.DoesUserHavePermissions(SPBasePermissions.EditListItems);
spList.DoesUserHavePermissions(SPBasePermissions.ManageLists);
spList.DoesUserHavePermissions(SPBasePermissions.AddListItems);
spList.DoesUserHavePermissions(SPBasePermissions.AddListItems)
Thank you !
I found a solution mentioned in this Blog for listItems permissions, and it worked fine for list.
the solution is as follow:
private static bool DoesUserHasPermission(ClientContext context, List list, PermissionKind permissionKind)
{
context.Load(list, t => t.EffectiveBasePermissions);
context.ExecuteQuery();
return list.EffectiveBasePermissions.Has(permissionKind);
}
From a client application the best approach would be use SharePoint web service. Sharepoint contains a lot of services that are usable for remote development by third-party developers.
In your case, I recommend use SharePoint Permission web service (http:///_vti_bin/permissions.asmx).
You could query Sharepoint about items permissions. Here is a step-by-step tutorial : http://jamestsai.net/Blog/post/Understand-SharePoint-Permissions-Part-2-Check-SharePoint-usergroup-permissions-with-Permissions-web-service-and-JavaScript.aspx

How to config Web References in Visual Studio for production environment

I'm developing an application which will upload documents to a sharepoint folder. Because my application will not run on a server environment, but in client machines, I decided to user the Web Services provided by Sharepoint to upload the documents (my sharepoint address + _vti_bin/copy.asmx) and check in the uploaded files (my sharepoint address + /_vti_bin/Lists.asmx).
My problem is with the my sharepoint address part. The Sharepoint I am using for development is of course different from the that the clients use. Since I have to add the Web References for the service at developing time in order to use it in the C# code, how should I approach?
I will have to obtain at least obtain the main parte of the sharepoint address - say https://sharepoint/projects/ProjectX/and declare my WS with it?
If it makes different, I am using WiX to deploy my application in the end, generating a .msi executable. My sharepoint is 2010 and I'm writing my application in VS2010 using .NET 4.0.
Thank you in advance
Thats Correct Pedro.
You should point my sharepoint address to the url of the website, not root site collection, but website you want to access the services.
You have then 2 options, you can change the address on the configuration file that the visual studio proxy generates as part of the build scripts (sorry dont know Wix, but I bet it can be done)
Or you can then set the url at runtime, it will ignore the one in the config file generated by Visual Studio:
WSS.Lists svc = new WSS.Lists();
svc.Url = my sharepoint address + "/_vti_bin/Lists.asmx"
Luis's answer is pretty much correct. Another approach you can do is create proxy classes using wsdl.exe. This creates a class instance which you can use in your project. Once you have the file you can just update the value of the variable URL so that it matches your sharepoint URL.
You can also update the constructor like below:
public Lists(string SERVER)
{
this.Url = "http://" + SERVER + "/_vti_bin/Lists.asmx";
}
This makes sure that you can use whatever SharePoint site you want or place it in configuration files too.

Magento Go C# requesting API fails to initialize

I am trying to connect to Magento API using C#. I am using Magento Go service and from what I've read I am able to use their API - I hope I am not wrong here. So here is what I did:
I added a Service Reference to http://mydomain.gostorego.com/api/v2_soap?wsdl=1, and just adding a service worked fine. Now I created a test class with GetStuff() method, which looks like this:
using ww.Feeds.MagnetoGoService;
public static string GetStuff()
{
MagnetoGoService.Mage_Api_Model_Server_V2_HandlerPortTypeClient s = new MagnetoGoService.Mage_Api_Model_Server_V2_HandlerPortTypeClient();
var login = s.login("username here", "key here");
return login.ToString();
}
When I run the program I get an error in first line saying:
Could not find default endpoint element that references contract 'MagnetoGoService.Mage_Api_Model_Server_V2_HandlerPortType' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
Any ideas what this may be? Do I have to set something up in my Magento Go settings? Or maybe using Magento Go is not allowing API access?
Thanks a lot.
Forget SOAP with c# you will pull your hair out. Download Charls Cook's xml-rpc api libary for c# and use the xml-rpc method. You won't get all the snazzy intellisense but at least it will work. There's also c# solution from ez.newsletter they released with Cook's library demonstrating how to use 80% of the magento api calls.
Cook's library xml-rpc.net
http://www.xml-rpc.net/
ez.newsletter solution
http://code.google.com/p/csharlibformagexmlrpcapi/
If anyone ever has problems with this, my solution was this:
I used the reference in one project, but I actually called the class and had main program in another project. You need your Service reference to be in each project wherever you're using it. That fixed it! Alternatively you can create a new BasicHttpBinding() and putt all the options from app.config/web.config into that binder, then you don't need to reference to Service everywhere. I hope that helps!

Categories

Resources