We have a SharePoint server 2007 and we are trying to make few entries into the SharePoint using the c#.net code. I came to know that we can use the SharePoint Client SDK components. But no where I found the SDK for 2007 version of SharePoint .
Is it possible to use the SharePoint 2013 Client SDK components to access the SharePoint 2007 site and do all the get or update actions ?
I don't know if the 2013 SDK can be used for 2007 instances, but I know that the SharePoint 2007 SDK is available here.
Since SharePoint Client Components SDK consists of collection of client-side object model (CSOM) DLLs and CSOM is not supported in SharePoint 2007, there is no release of SharePoint Client SDK for 2007 version.
But you could utilize SharePoint 2007 Web Services for that purpose, the following example demonstrates how to consume SharePoint Web Services to create a List Item:
using System;
using System.Collections.Generic;
using System.Net;
using System.Xml;
namespace SharePoint.Client
{
public class ListsClient : IDisposable
{
public ListsClient(Uri webUri, ICredentials credentials)
{
_client = new Lists.Lists();
_client.Credentials = credentials;
_client.Url = webUri + "/_vti_bin/Lists.asmx";
}
public ListsClient(Uri webUri)
{
_client = new Lists.Lists();
_client.Url = webUri + "/_vti_bin/Lists.asmx";
}
/// <summary>
/// Create a List Item
/// </summary>
/// <param name="listName">List Name</param>
/// <param name="propertyValues">List Item properties</param>
/// <returns></returns>
public XmlNode CreateListItem(string listName,Dictionary<string,string> propertyValues)
{
var payload = new XmlDocument();
var updates = payload.CreateElement("Batch");
updates.SetAttribute("OnError", "Continue");
var method = payload.CreateElement("Method");
method.SetAttribute("ID", "1");
method.SetAttribute("Cmd", "New");
foreach (var propertyValue in propertyValues)
{
var field = payload.CreateElement("Field");
field.SetAttribute("Name", propertyValue.Key);
field.InnerText = propertyValue.Value;
method.AppendChild(field);
}
updates.AppendChild(method);
return _client.UpdateListItems(listName, updates);
}
public void Dispose()
{
_client.Dispose();
GC.SuppressFinalize(this);
}
protected Lists.Lists _client; //SharePoint Web Services Lists proxy
}
}
Usage
How to create a Task item:
using (var client = new SPOListsClient(webUrl, userName, password))
{
var taskProperties = new Dictionary<string, string>();
taskProperties["Title"] = "Order approval";
taskProperties["Priority"] = "(2) Normal";
var result = client.CreateListItem(listTitle, taskProperties);
}
References
SharePoint 2007 Web Services
Lists.UpdateListItems Method
Related
I have a .NET Core 2.2 API running on IIS on a Windows Server 2012 R2 Datacenter machine. It uses the DLLs from Nuget package Microsoft.SharePointOnline.CSOM. But it throws exception One or more errors occurred. (The process has no package identity. (Exception from HRESULT: 0x80073D54)) when calling method ClientContext.ExecuteQueryAsync().
I have followed the following guide: https://rajujoseph.com/getting-net-core-and-sharepoint-csom-play-nice/ . I have tried two solutions. The first was creating a .NET Core Console solution that calls the DLL containing the SharePoint CSOM code. Then I tried calling the DLL from a .NET Core 2.2 API running on IIS on a Windows Server 2012 R2 Datacenter machine. But both solutions throw the same exception as mentioned above One or more errors occurred. (The process has no package identity. (Exception from HRESULT: 0x80073D54)).
The SharePointHelper.dll code:
using Microsoft.SharePoint.Client;
using System;
using System.Collections.Generic;
using System.Text;
namespace SharePointHelper
{
public class SharePointHelper
{
public SharePointHelper() { }
public void WriteFilesAndFolders(string siteUrl, string listName, string username, string password)
{
using (var context = new ClientContext(siteUrl))
{
context.Credentials = new SharePointOnlineCredentials(username, password);
var folder = context.Web.GetFolderByServerRelativeUrl(listName);
var subFolders = folder.Folders;
var files = folder.Files;
context.Load(folder);
context.Load(subFolders);
context.Load(files);
if (context.HasPendingRequest)
context.ExecuteQueryAsync().Wait();
var subFolderEnumorator = subFolders.GetEnumerator();
var filesEnumerator = files.GetEnumerator();
PrintValues(subFolderEnumorator);
PrintValues(filesEnumerator);
}
}
private void PrintValues(IEnumerator<Folder> enumerator)
{
while (enumerator.MoveNext())
Console.WriteLine(enumerator.Current.Name);
}
private void PrintValues(IEnumerator<File> enumerator)
{
while (enumerator.MoveNext())
Console.WriteLine(enumerator.Current.Name);
}
}
}
The .NET Core 2.2 service code calling the method in the SharePointHelper.dll:
public void SharePointTest()
{
string siteUrl = #"https://somecompany.sharepoint.com/sites/Test";
string listName = "Documents";
string username = "myemail#somecompany.com";
string password = "mypassword";
var sharePointHelper = new SharePointHelper.SharePointHelper();
sharePointHelper.WriteFilesAndFolders(siteUrl, listName, username, password);
}
I expect the SharePointHelper.dll to connect and get a response from SharePoint. But exception One or more errors occurred. (The process has no package identity. (Exception from HRESULT: 0x80073D54)) is thrown.
You can solve this problem to use SharePoint with .NET Core by simply installing the TTCUE.NetCore.SharepointOnline.CSOM Nuget package. No reason to follow the linked guide unless you want to understand how to do the workaround in depth.
I'm trying to read an xlsx file, and I got a basic overview from This Codeproject Link
Now, I'm getting the following exception message:
The code segment related to this exception is given below:
public static sst SharedStrings;
/// <summary>
/// All worksheets in the Excel workbook deserialized
/// </summary>
/// <param name="ExcelFileName">Full path and filename of the Excel xlsx-file</param>
/// <returns></returns>
public static IEnumerable<worksheet> Worksheets(string ExcelFileName)
{
worksheet ws;
using (ZipArchive zipArchive = ZipFile.Open(ExcelFileName, ZipArchiveMode.Read))
{
SharedStrings = DeserializedZipEntry<sst>(GetZipArchiveEntry(zipArchive, #"xl/sharedStrings.xml"));
foreach (var worksheetEntry in (WorkSheetFileNames(zipArchive)).OrderBy(x => x.FullName))
{
ws = DeserializedZipEntry<worksheet>(worksheetEntry);
ws.NumberOfColumns = worksheet.MaxColumnIndex + 1;
ws.ExpandRows();
yield return ws;
}
}
}
After some searching, I figured out that I needed to target .NET 4.5 or above version, (I'm targetting 4.6.1, but I also have tried 4.5, still same results). Also, as far as the dependencies are concerned, my references look like this:
After doing all this, I'm still getting the exception mentioned above, and have no idea why this is happening.
EDIT 1: I've been through This StackOverflow Link, where I figured that I need the latest DLLs. I went to the Nuget Package Manager, and there were "No Packages Found" which were available for the updates.
I have tried .NET 4.6.1 and 4.6.2. Both work OK for me.
My Visual Studio is Community Edition 2017
The project references:
Note that System.IO.Compression.ZipFile is not referenced. It was not possible to reference it in my environment.
Use Workbook.Worksheets() or declare the calling class as sub-class of Excel.Workbook.
Excel is the namespace of the CodeProject article source which provides the necessary classes.
using Excel;
using System;
namespace akExcelAsZipDemo
{
class Program : Workbook
{
// from
// https://www.codeproject.com/tips/801032/csharp-how-to-read-xlsx-excel-file-with-lines-ofthe
//
// inspired:
// https://github.com/ahmadalli/ExcelReader
static void Main(string[] args)
{
const string fileName = #"E:\AK\export.xlsx";
var worksheets = Worksheets(fileName);
foreach (worksheet ws in worksheets)
{
Console.WriteLine($"cols={ws.NumberOfColumns} rows={ws.Rows.Length}");
}
Console.WriteLine();
}
}
}
We need to work on .net based web application that will upload files to Amazon S3 Storage bucket using admin panel of the app and clients will be given to downloadable files with client.aspx file.
We looked at few example and got confused with some of the sample code for downloading non public files from S3 storage. one such example is below
AmazonS3Config config = new AmazonS3Config()
{
RegionEndpoint = RegionEndpoint.USEast1
};
IAmazonS3 client = new AmazonS3Client(accessKey, secretKey, config);
string dest = System.IO.Path.GetTempPath() + "event.mp4";
using (client)
{
GetObjectRequest request = new GetObjectRequest() { BucketName = "bucketname" + #"/" + "videos2015", Key = "event.mp4" };
using (GetObjectResponse response = client.GetObject(request))
{
response.WriteResponseStreamToFile(dest);
}
}
Response.Clear();
Response.AppendHeader("content-disposition", "attachment; filename=" + "dynamic_filename.png");
Response.ContentType = "application/octet-stream";
Response.TransmitFile(dest);
Response.Flush();
Response.End();
When user click on the link following code gets executed on web server and code downloads file on the web server and then serves the same file to client... if i am not wrong. Is there not a way that we can serve file for download directly from the AWS S3 storage.
In above case it is waste of server resources and increases the download time also.
Out files on AWS are not Public they are non public so the url is not accessible directly from client browsers as is in case of public content type
The pre-signed urls are indeed what you are looking for. Since you are using C#, here is a link to some useful code examples:
http://docs.aws.amazon.com/AmazonS3/latest/dev/ShareObjectPreSignedURLDotNetSDK.html
There is no need to upload files to s3 thru your webserver, they can be sent directly. Same thing on the download, download directly from S3 - don't copy them to EC2 first, you would be wasting bandwidth and processing resources.
You can use Minio-dotnet client library Its Open Source & supports compatible S3 API.
Here is an example for PresignedPostPolicy
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Minio;
namespace Minio.Examples
{
class PresignedPostPolicy
{
static int Main()
{
/// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname and
/// my-objectname are dummy values, please replace them with original values.
var client = new MinioClient("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");
PostPolicy form = new PostPolicy();
DateTime expiration = DateTime.UtcNow;
form.SetExpires(expiration.AddDays(10));
form.SetKey("my-objectname");
form.SetBucket("my-bucketname");
Dictionary <string, string> formData = client.PresignedPostPolicy(form);
string curlCommand = "curl ";
foreach (KeyValuePair<string, string> pair in formData)
{
curlCommand = curlCommand + " -F " + pair.Key + "=" + pair.Value;
}
curlCommand = curlCommand + " -F file=#/etc/bashrc https://s3.amazonaws.com/my-bucketname";
Console.Out.WriteLine(curlCommand);
return 0;
}
}
}
And below one for PresignedPutObject
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Minio;
namespace Minio.Examples
{
class PresignedPutObject
{
static int Main()
{
/// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname and
/// my-objectname are dummy values, please replace them with original values.
var client = new MinioClient("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");
Console.Out.WriteLine(client.PresignedPutObject("my-bucketname", "my-objectname", 1000));
return 0;
}
}
}
Hope it helps.
PS: I work for Minio
I have tried to read Microsoft Outlook contact using Microsoft Outlook 15.0 object library DLL, it works locally; when it comes to client, we do not know what version of Outlook is the client using. How to read if each client having different versions of Outlook?
I want to read the contact with any version of Microsoft Outlook Version using C#.
If you have any open source code, it helps a lot.
Please look at my code and help me where am doing wrong.
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Runtime.InteropServices;
using MsOutlook = Microsoft.Office.Interop.Outlook;
namespace Test
{
public class OutlookMailManager : IDisposable
{
public OutlookMailManager() { }
/// <summary>
/// Get MailContacts From Google (Gmail) using the provided username and password.
/// </summary>
/// <param name="maxEnries">Total number of entries to return</param>
/// <returns>The addressbook entries</returns>
public string GetOutlookMailContacts(int maxEnries)
{
MsOutlook.ApplicationClass OutlookApplication = new MsOutlook.ApplicationClass();
MsOutlook.NameSpace outlookNameSpace = OutlookApplication.GetNamespace("MAPI");
MsOutlook.MAPIFolder contactsCollection = outlookNameSpace.GetDefaultFolder(MsOutlook.OlDefaultFolders.olFolderContacts);
Microsoft.Office.Interop.Outlook.Items folderItems = contactsCollection.Items;
string rtnStr = "";
if (folderItems.Count > 0)
{
for (int i = 1; folderItems.Count >= i; i++)
{
object contactObj = folderItems[i];
if (contactObj is MsOutlook.ContactItem)
{
MsOutlook.ContactItem contact = (MsOutlook.ContactItem)contactObj;
rtnStr += contact.FullName + " (" + contact.BusinessTelephoneNumber + ")\n";
}
Marshal.ReleaseComObject(contactObj);
if (i == maxEnries) break;
}
}
Marshal.ReleaseComObject(folderItems);
Marshal.ReleaseComObject(contactsCollection);
Marshal.ReleaseComObject(outlookNameSpace);
return rtnStr;
}
}
}
You just need to use the PIAs corresponding the lowest Outlook version you need to support. Thus, you will be sure that only properties and methods existing in all Outlook versions are used. See C# app automates Outlook (CSAutomateOutlook) for the sample project.
Currently its working fine with my Outlook 2003 Version
CheckOut this code but i havent tested with different outlook version.but
Add Microsoft.Office.Interop.Outlook dll in reference
Microsoft.Office.Interop.Outlook.Items OutlookItems;
Microsoft.Office.Interop.Outlook.Application outlookObj;
MAPIFolder Folder_Contacts;
private void Form1_Load(object sender, EventArgs e)
{
outlookObj = new Microsoft.Office.Interop.Outlook.Application();
Folder_Contacts = (MAPIFolder)outlookObj.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts);
OutlookItems = Folder_Contacts.Items;
for (int i = 0; i < OutlookItems.Count; i++)
{
Microsoft.Office.Interop.Outlook.ContactItem contact = (Microsoft.Office.Interop.Outlook.ContactItem)OutlookItems[i + 1];
MessageBox.Show("FirstName:"contact.FirstName +" "+"LastName:"+contact.LastName +" "+"Emailid:"+contact.Email1Address);
}
}
I want to programatically connect to TFS and be able to checkout and checkin the files. For that purpose, I am using the following code (some private information omitted), however, I get the "not having sufficient permissions error", I have checked with the administrator and he has given me both read and write permissions, can anyone please help me. Here's the code:
using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
namespace CodeGeneration
{
public class CheckInTFS
{
public static void ProcessFile()
{
var tfs = new TfsTeamProjectCollection(new Uri("http://tfs"));
var versionControlServer = tfs.GetService<VersionControlServer>();
var workspace = versionControlServer.GetWorkspace(#"D:\Test");
#region Checkout File
var file = #"D:\EnumGeneration.cs";
workspace.PendEdit(file);
var pendingChange = workspace.GetPendingChanges();
#endregion
#region Checkin File
workspace.CheckIn(pendingChange, "Test Comment!");
#endregion
}
}
}
The error which I receive is this:
Also, I have looked at the permissions from This MS Page and I have GENERIC_READ and GENERIC_WRITE permissions.
I found this sample, try with this and let me know if you still have persmisson problems when adapting and running this
using System;
using System.Collections.ObjectModel;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Framework.Common;
using Microsoft.TeamFoundation.Framework.Client;
namespace TfsApplication
{
class Program
{
static void Main(String[] args)
{
// Connect to Team Foundation Server
// Server is the name of the server that is running the application tier for Team Foundation.
// Port is the port that Team Foundation uses. The default port is 8080.
// VDir is the virtual path to the Team Foundation application. The default path is tfs.
Uri tfsUri = (args.Length < 1) ?
new Uri("http://Server:Port/VDir") : new Uri(args[0]);
TfsConfigurationServer configurationServer =
TfsConfigurationServerFactory.GetConfigurationServer(tfsUri);
// Get the catalog of team project collections
ReadOnlyCollection<CatalogNode> collectionNodes = configurationServer.CatalogNode.QueryChildren(
new[] { CatalogResourceTypes.ProjectCollection },
false, CatalogQueryOptions.None);
// List the team project collections
foreach (CatalogNode collectionNode in collectionNodes)
{
// Use the InstanceId property to get the team project collection
Guid collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]);
TfsTeamProjectCollection teamProjectCollection = configurationServer.GetTeamProjectCollection(collectionId);
// Print the name of the team project collection
Console.WriteLine("Collection: " + teamProjectCollection.Name);
// Get a catalog of team projects for the collection
ReadOnlyCollection<CatalogNode> projectNodes = collectionNode.QueryChildren(
new[] { CatalogResourceTypes.TeamProject },
false, CatalogQueryOptions.None);
// List the team projects in the collection
foreach (CatalogNode projectNode in projectNodes)
{
Console.WriteLine(" Team Project: " + projectNode.Resource.DisplayName);
}
}
}
}
}
taken from here
http://msdn.microsoft.com/en-us/library/bb286958.aspx
The following code snippet did the trick:
var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(TFS_SERVER));
var workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(FULL_FILE_PATH);
var workspace = workspaceInfo.GetWorkspace(tfs);