Skip to main content

Windows Live - SkyDrive

Windows LIVE series:
Astazi o sa vorbim despre cum putem accesa SkyDrive.
Pentru a putea avea acces la datele pe care un user le are pe SkyDrive este nevoie ca la logare sa setam scopul "wl.skydrive". Avand setat acest scope o sa putem accesa orice informatie pe care userul o are pe SkyDrive.
WL.init({ client_id: {idClient}, redirect_uri: {ourRedirectUrl} });
{ "scope": "wl.skydrive" },
function (response) {
if (response.status == "connected") {
alert("Utilizator conectat");
else {
alert("Autentificare esuata");
Dupa ce utilizatorul s-a logat tot ce ne-a mai ramas este sa apelam API-ul care il avem la dispozitie. Fiecare element care ne vine dupa o interogare o sa contina date precum tipul ementului( daca e folder sau fisier - ce tip de fisier), nume fisier, id, dimensiune etc. Aceste informatii sunt foarte asemanatoare cu cele pe care le avem cand suntem intr-un director de pe disk-ul local. Din JS pentru a aduce toate elementele din root trebuie sa facem urmatorul apel:
 WL.api({ path: ""/me/skydrive/files", method: "GET" }, onGetRootItemsComplete);
function onGetRootItemsComplete(response) {
if (response.error) {
alert("A aparut o eroare");
var items =;
var foundFolder = 0;
for (var i = 0; i < items.length; i++)
// item[i].type - tipul fisierului. Valore este "fo-lder" daca elementul este un folder
// daca ar fi un fisier aceast camp ar avea valoarea "file"
// item[i].name - numele la element
// item[i].id - id unic a elementului din SkyDrive

O sa avem nevoie de id, daca vrem de exemplu sa facem download la continutul unui fisier.
Pentru a putea vedea toate folderele, albumele de poze si fisierele din root a unui user pe de Skydrive e nevoie sa facem un request cu path-ul setat spre: me/skydrive/files
Pentru a accesa fisierele unui folder este nevoie sa apelam urmatorul path: {folderId}/files . Exact la fel se face daca vrem sa aducem pozele dintr-un albul: {album_id}/files.
Dar cum putem sa adaugam un nou folder pe SkyDrive. Pentru acest lucru avem nevoie de numele la folder, o scurta descriere si locatia unde dorim sa il adaugam. Mai jos puteti gasi un exemplu in C#:
Dictionary<string, object> newFolderData = new Dictionary<string, object>();
folderData.Add("NewFolderName", "New folder description");
LiveConnectClient liveConnectClient = new LiveConnectClient(session);
liveConnectClient.PostCompleted +=
new EventHandler<LiveOperationCompletedEventArgs>(CreateFolderPostCompleted);
client.PostAsync("me/skydrive/files/BaseFolder", newFolderData);
void CreateFolderPostCompleted(object sender, LiveOperationCompletedEventArgs e)
// Daca e.Error este diferit de NULL, atunci actiunea nu s-a terminat cu succes.
Daca in al doilea exemplu am vazut cum putem itera printr-un folder, acuma va propun sa download un fisier de pe SkyDrive. Odata ce avem id-ul la fisierul pe care vrem sa il copiem local, e nevoie sa apelam direct metoda download din JS sau DownloadAsync din C#. Pentru exemplul de mai jos am ales tot varianta C#:
client.DownloadCompleted +=
new EventHandler<LiveDownloadCompletedEventArgs>(OnFileDownloadCompleted);
void OnFileDownloadCompleted(object sender, LiveDownloadCompletedEventArgs e)
// e.Result o sa contina fisierul nostru.
// Nu uitati sa faceti close la Result, deoarece este un stream: e.Result.Close();
Dupa cum am putut vedea prin intermediul API-ului este foarte simplu sa lucram cu SkyDrive. Nu uitati ca SkyDrive nu permite prin intermediul API-ului upload-ul la orice fel de fisiere. Asigurativa inainte sa faceti upload ca fisierul vostru este suportat. Din interfata web puteti uploada orice fel de fisiere.
Fisierele care se pot copia pe SkyDrive prin intermediul API sunt:
  • PDF, txt + fisiere Office precum Word, Excell, etc
  • poze in orice format supotat de Windows
  • audio doar in format wav
  • video in format wmv sau H.264
Orice tip de fisier poate sa fie adaugat din brower de exemplu. Trebuie tinut cont ca, chiar daca din API manipulam datele unui user( schimba vizibilitatea unui fisier), nu putem sa restrictionam accesul la fisere a.i. userul sa nu le poata accesa.


Popular posts from this blog

ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded

Today blog post will be started with the following error when running DB tests on the CI machine:
threw exception: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See for more information. at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName) This error happened only on the Continuous Integration machine. On the devs machines, everything has fine. The classic problem – on my machine it’s working. The CI has the following configuration:

TeamCity.NET 4.51EF 6.0.2VS2013
It seems that there …

How to check in AngularJS if a service was register or not

There are cases when you need to check in a service or a controller was register in AngularJS.
For example a valid use case is when you have the same implementation running on multiple application. In this case, you may want to intercept the HTTP provider and add a custom step there. This step don’t needs to run on all the application, only in the one where the service exist and register.
A solution for this case would be to have a flag in the configuration that specify this. In the core you would have an IF that would check the value of this flag.
Another solution is to check if a specific service was register in AngularJS or not. If the service was register that you would execute your own logic.
To check if a service was register or not in AngularJS container you need to call the ‘has’ method of ‘inhector’. It will return TRUE if the service was register.
if ($injector.has('httpInterceptorService')) { $httpProvider.interceptors.push('httpInterceptorService&#…

Fundamental Books of a Software Engineer (version 2018)

More then six years ago I wrote a blog post about fundamental books that any software engineer (developer) should read. Now it is an excellent time to update this list with new entries.

There are 5 different categories of books, that represent the recommended path. For example, you start with Coding books, after that, you read books about Programming, Design and so on.
There are some books about C++ that I recommend not because you shall know C++, only because the concepts that you can learn from it.


Writing solid codeCode completeProgramming Pearls, more programming pearls(recommended)[NEW] Introduction to Algorithms


Refactoring (M. Fowler)Pragmatic ProgrammerClean code[NEW] Software Engineering: A Practitioner's Approach[NEW] The Mythical Man-Month[NEW] The Art of Computer Programming


Applying UML and Patterns (GRASP patterns)C++ coding standards (Sutter, Alexandrescu)The C++ programming language (Stroustrup, Part IV)Object-oriented programming (Peter Coad)P…