mardi 16 octobre 2012

PHP Curl wamp Et windows


L'installation de curl sur windows peut poser des problèmes, il ne suffit pas d'activer l'extension du fichier php.ini mais il faut s'assurer que l'extension php_curl correspond avotre version php.

la correction de ce problème réside dans la modification de ce fichier par le DLL adéquat a la version de PHP installé.
pour la version php 5.4.3, la version curl installé par défaut présente des bugs. d'où il faut la modifier par le fichier suivant

php5.4.3 => http://www.morningtime.com/sites/default/files/attachments/book/188/php_curl-5.4.3-VC9-x64.zip


mardi 3 avril 2012

Add attachements on SharePoint Item

Hi, developpers today i'm writing this duing to lack of information in the internet about adding attachements on sharepoint Item client side. So first of all if you are using "Client context" it's hight time to know that it cant do every thing for you.
This tutorial is about adding attachement using Sharepoint web services.
So if you are trying to do the same I think you are enought able to consume a web service. so try to connect on your sharepoint Web service (the one that ends with "http://your_domain/_vti_bin/lists.asmx")  and name it "ListsService 

ListsWebService.Lists ListsService = new ListsWebService.Lists();

Here you are with full controle on your sharepoint. So now you can start reading your file to attach.


 

 FileStream fStream = System.IO.File.OpenRead(filePath);
 byte[] contents = new byte[fStream.Length];
 fStream.Read(contents, 0, (int)fStream.Length);
 fStream.Close();

gooood nice #MOMTAZ you are ready to attach it to your Item, ToDo you have to know the ID of your Item on the sharepoint, Go Get it I'm weating for you, the ListName or GUID (I'm using the ID of the List) and the fileName. and just call the methode AddAttachement of the web service.

ListsService.AddAttachment(GUID, ItemId, fileName, contents);

I'm using thoes params as exemple: 
  • GUID:c3a01ef7-95ba-4230-8754-ea288f93fd31
  • ItemId: 250
  • fileName: doc1\folder2\XXXXX.docx (this is not an xxx content)
  • contents: {bytes[12]}

So this is what we got (just copy and have fun):

ListsWebService.Lists ListsService = new ListsWebService.Lists();
FileStream fStream = System.IO.File.OpenRead(filePath);
byte[] contents = new byte[fStream.Length];
fStream.Read(contents, 0, (int)fStream.Length);
fStream.Close();
ListsService.AddAttachment(GUID, ItemId, fileName, contents);

vendredi 23 mars 2012

Sharepoint get ListItems with childs using clientcontext and CamlQuery

When trying to update some folder metadata i was unable to get subfolders as ListItem. I finnally came with this solution:


CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<View Scope=\"RecursiveAll\"> <Query></Query></View>";
var items = MyList.GetItems(camlQuery);
clientContext.Load(items, item => item.Where(i => i.DisplayName == FolderName));
clientContext.ExecuteQuery();

This code allow you to find a folder by name in a sharepoint list recursively (lookin your List Items and their childs.

Sharepoint: Creating a DocSet programmatically (client context,Silverlight side))

If you surf arround the web looking for a code to create a "Document Set" Item ina sharepoint platform using ClientContext you will get bored by unusfull solution. So I decided to help  you:


if (DocumentSet_IsEnabled(container.Title))
{
 ListItem docSet = null;
 List list = clientContext.Web.Lists.GetByTitle(container.Title);
 clientContext.Load(list);
 clientContext.ExecuteQuery();
 docSet = DocumentSet_Create(list, folder, itemName);
}

public bool DocumentSet_IsEnabled(string listName)
{
 List list = this.Context.Web.Lists.GetByTitle(listName);
 ContentTypeCollection listContentTypes = list.ContentTypes;
 Context.Load(listContentTypes, types => types.Include(type => type.Name)); 
 var result=Context.LoadQuery(
 listContentTypes.Where(
 c => c.Name == "Document Set" || c.Name == "Ensemble de documents"));
 Context.ExecuteQuery();
 return result.Count() == 1;
}

public ListItem DocumentSet_Create(List list, Folder folder, String itemNamestring description = "")
{
 ListItem docSet = null;
 ListItemCreationInformation newItemInfo = new ListItemCreationInformation();
 ContentType contentType = null;    
 newItemInfo.UnderlyingObjectType = FileSystemObjectType.Folder;
 newItemInfo.LeafName = itemName;
 if (folder != null)
  newItemInfo.FolderUrl = folder.ServerRelativeUrl;
 
 docSet = list.AddItem(newItemInfo);
 contentType = this.DocumentSet_GetContentType(list);
 docSet["ContentTypeId"] = contentType.Id.ToString();
try
{
 docSet.Update();
 Context.ExecuteQuery();
}
catch
{docSet = null;}
 return docSet;
}

jeudi 22 mars 2012

Update ["Created by"] (Author) & ["Modified By"](Editor) in a sharepoint Item)

Si vous voulez changer les metadonnées d'un dossier et vous avez utilisé :
myfolder.Folders.Add(subFolder);
vous pouvez changer les "Metadata"  de cette façon:

CamlQuery camlQuery = new CamlQuery();
user=clientContext.Web.EnsureUser(UserName);              
clientContext.Load(user);           
clientContext.ExecuteQuery();
var items = YourSharepointList.GetItems(camlQuery);
clientContext.Load(items,item =>item.Where(i=>i.DisplayName==subFolder));
clientContext.ExecuteQuery();
Utils utils = new Utils(_clientContext);
if ((user != null)&& (items.Count>0))
{
 items[0]["Author"] = user;
 items[0]["Editor"] = user;
 items[0].Update();
 clientContext.ExecuteQuery();
}


Si vous voulez changer les metadonnées d'un DocSet  utilisez cette méthode après avoir créé le DocSet:

private void ManageFields(ListItem listItem)
        {
            Utils utils = new Utils(_clientContext);
            var user = FieldUserValue.FromUser(AuthorName);
            var xuser = utils.User_GetByLoginName(AuthorName);
            if ((xuser.ServerObjectIsNull != null))
                listItem["Author"] = user;
            user = FieldUserValue.FromUser(EditorName);
            xuser = utils.User_GetByLoginName(EditorName);
            if ((xuser.ServerObjectIsNull != null))                 listItem["Editor"] = user;             DateTime dt;             if (DateTime.TryParse(item.CreationDate, out dt))                 listItem["Created"] = dt;             if (DateTime.TryParse(item.LastModificationDate, out dt))                 listItem["Modified"] = dt;             listItem.Update();             clientContext.ExecuteQuery();         }