GithubHelp home page GithubHelp logo

galeassim / sitefinitynet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from timw255/sitefinitynet

0.0 2.0 0.0 3.55 MB

C# client that adds Sitefinity connectivity to third-party applications.

sitefinitynet's Introduction

Sitefinity.NET - .NET REST Client for Telerik Sitefinity CMS

Got an idea or better way to do something? I welcome pull requests. Please send them. :)

Sitefinity.NET is a C# client that adds Sitefinity connectivity to third-party applications.

What works

  • Querying blogs, blog posts, albums, images and news items
  • Creating new blogs, blog posts, albums, images and news items

What might work

I wrote methods for a bunch of stuff but haven't tested them yet.

  • Deleting content
  • Batch deleting content
  • Get and Set ratings of content
  • Batch publishing and un-publishing content
  • Deleting temp versions of content

Before we go any further...

This is a public release of a "proof of concept". It's meant to get the ball rolling, so to speak. What I'm saying here is don't blame me if you blow up your site with it.

If you're OK with that and ready for some fun. Here we go!

Authentication (where it all begins...)

Create an instance of SitefinityClient and authenticate.

using SitefinityNET.Managers.GenericContent;
using SitefinityNET.Sitefinity.Models.GenericContent;

SitefinityClient sf = new SitefinityClient("admin", "password", "http://localhost");

sf.SignIn();

Managers

Managers are the worker bees of this operation.

Something to note: Currently, manager methods that begin with 'List' return List<dynamic> so if you don't know exactly what property you're looking for, some debugging may be necessary.

LibrariesManager manager = new LibrariesManager(sf);

// This is how we build the list of filters to include
Dictionary<Utility.ContentFilter, string> filters = new Dictionary<Utility.ContentFilter, string>();
filters.Add(Utility.ContentFilter.TitleLike, "Default"); // Other options include: TitleEquals, IdEquals

// For convienience
string filterString = Utility.BuildFilterString(filters);

var items = manager.ListAlbums(filterString, 0, 50);

var newItem = new Image();

string newItemTitle = "New Image Title";

newItem.Title = newItemTitle;
newItem.UrlName = Regex.Replace(newItemTitle.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");

Guid parentId = items.First().Id;

Image item = manager.CreateImage(newItem, parentId, false);

Uploading Binary Content

Upload binary content (images, document, etc.) by using the UploadContent method of the manager you're working with.

This example pulls the image from a remote server but the data could come from a database or local filesystem if it needed to.

if (item.Id != Guid.Empty)
{
	string imageUrl = "http://www.codemoar.com/images/default-source/demo/sitefinity-logo.png";
	
	using (var webClient = new WebClient())
	{
		byte[] imageBytes = webClient.DownloadData(imageUrl);

		// Upload the file and tell Sitefinity which item it belongs to (via item.Id)
		manager.UploadContent(parentId, item.Id, imageBytes, "sitefinity-logo.png", "image/png");
	}
}

Signing Out (because it's polite...)

Make sure to sign out when your done.

sf.SignOut();

Support for Custom Fields

Custom field values can be set on content. The fields must have already been created in Sitefinity for the values to stick.

var newItem = new Blog();

string newItemTitle = "New Blog";

newItem.Title = newItemTitle;
newItem.UrlName = Regex.Replace(newSingleItemTitle.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");

newItem.AddProperty("VeryCustomShortTextField", "Some Value");
newItem.AddProperty("VeryCustomNumberField", 42);
newItem.AddProperty("VeryCustomYesNoField", true);

var returnedItem = manager.CreateBlog(newItem);

It's possible to check for values when content is recieved from Sitefinity.

Guid itemId = Guid.Parse("8f990bfd-13ef-6fb1-b1e0-ff0000cacdaa");

var item = manager.GetBlog(itemId);

if (item.HasProperty("VeryCustomShortTextField"))
{
	var fieldValue = item.GetValue<string>("VeryCustomShortTextField");
}

item.SetValue("VeryCustomShortTextField", "Some Other Value");

sitefinitynet's People

Contributors

timw255 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.