« TonesNotes Documentation | Main | New release of TonesNotes for Dottext supports posting images from Word »

Changes to .Text for Image Posting using TonesNotes

The latest version of TonesNotes lets you post blog entries from Word that contain images:

Here is the change required of 0.95 vintage Dottext codebase.

Add the following method to the SimpleBlogService.asmx.cs file:

/// <summary>

/// Add an image to a specified gallery and return the url by which it will be accessible.

/// </summary>

/// <param name="username"></param>

/// <param name="password"></param>

/// <param name="gallery">Title of the target gallery, gallery will be created if it doesn't exist.</param>

/// <param name="postdate">Date to associate with the image. Not currently supported by the data model.</param>

/// <param name="title">Title for the image.</param>

/// <param name="description">Description for the image.</param>

/// <param name="categories">Array of categories to associate with the image. Not currently supported by the data model.</param>

/// <param name="filename">The non-path image filename including extension. Note that currently filenames must be unique within a gallery.</param>

/// <param name="data">Image file data in on-disk format matching the filename's extension.</param>

/// <returns>A url in the form http://blogs.mydomain.com/myblog/8/o_filename.jpg, where 8 is the integer CategoryID assigned to the gallery.

/// The returned url is an absolute url with a "o_" prefix on the filename.

/// Caller can make the prefix "t_" for thumbnail and "r_" for standard size.</returns>

[WebMethod(MessageName="AddImageToGallery",Description="Insert an image into a gallery with Categories",EnableSession=false)]

public string AddImageToGallery

      ( string username

      , string password

      , string gallery

      , DateTime postdate

      , string title

      , string description

      , string[] categories

      , string filename

      , byte[] data

      ) {

 

      BlogConfig config = Config.CurrentBlog(Context);

      CheckUser(username,password);

 

      int categoryID = 0;

 

      // Lookup the categoryID of gallery (gallery is the title).

      LinkCategoryCollection lcc = Links.GetCategories(CategoryType.ImageCollection, false);

      foreach (LinkCategory lc in lcc) if (string.Compare(lc.Title, gallery, true) == 0) { categoryID = lc.CategoryID; break; }

 

      // If gallery doesn't exist, try creating it.

      if (categoryID == 0) {

            LinkCategory category = new LinkCategory();

            category.CategoryType = CategoryType.ImageCollection;

            category.Title = gallery;

            category.IsActive = false;

            category.Description = "Images uploaded with new posts.";

            categoryID = Links.CreateLinkCategory(category);

            if (categoryID == 0) throw new Exception("CategoryID is zero");

      }

 

      // Insert the new image into the selected gallery.

      // This puts three copies (thumbnail, standard size, original size) of the image on disk under the "images" folder

      // and adds a record to the blog_Images table.

      Image image = new Image();

      image.CategoryID = categoryID;

      image.Title = title;

      image.IsActive = true;

      image.File = Images.GetFileName(filename);

      image.LocalFilePath = Images.LocalGalleryFilePath(Context, categoryID);

      int imageID = Images.InsertImage(image, data); 

 

      if (imageID == 0) throw new Exception("ImageID is zero");

 

      string baseImagePath = Images.HttpGalleryFilePath(Context, image.CategoryID);

 

      return baseImagePath + image.OriginalFile;

}

 

 

 

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)