Generally, when writing code to communicate with web services in C#, the usual process is to add a service reference. Visual Studio then automatically creates all the wrapper classes/objects for you that you need in order to talk with the service. However, sometimes, you want greater control. This article explains and gives you the code needed to work with a regular SOAP based web service without adding a reference.
Use this solution for uploading files to any REST endpoint using C#. Unlike the WebClient.UploadFile method from the .NET framework, this technique allows you to pass custom parameters that may be required by your API.
For quick reference: C# and PowerShell code snippets to grab the SharePoint central admin url for a farm.
Generally, you would use RunWithElevatedPrivileges to elevate permissions and execute a block code as the application pool account. But this doesn’t work nicely in console apps.
Fix for new SPSite object error: “The Web application at [URL] could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.”
Sometimes, your C# SharePoint application may not execute in a SharePoint context. This trick to create a fake SPContext object in a non-SharePoint context, may come in handy in such situations.