Transmission Watch Folders, Samba and Windows

Posted by beakersoft | Posted in Linux | Posted on 02-11-2011


Just a quick post about an issue i’ve been having for a while that i’ve just managed to solve. A while ago I re-built my home nas, using Ubuntu Server instead of Freenas. I installed Transmission for downloading torrents, but could never get the watch folder functionality working correctly. I would setup the folder, tell the transmission config about it but everytime i dropped a file in the folder, it would just get ignored.

Well, tonight I have just managed to get it working. It turned out it was a permissions issue. When I dropped a .torrent file into the folder from my Windows 7 machine (shared out via samba), and looked at the permissions of the file (via an ls -al command from putty) the owner and group was set to nobody and nobody. This was even after I had set the owner/group on the folder with the -R (re-curse) option. If I set the ower/group manually from putty to the ‘debian-transmission’ user, transmission then picked up the file as expected and started the download.

So, I figured it must have been an issue with me dropping in the files from my Windows 7 machine via a Samba share. I had a look through the Samba docs, and came across the inherit owner option. By default this is no, so I amended my smb.conf file and placed inherit owner = yes in the global section, then restarted the smb service.

After the restart, I dropped another .torrent file in via my Windows machine and checked its permissions again. This time the owner was set to ‘debian-transmission’, and after a few seconds Transmission kicked in and started to download the file. Problem solved! Now I can look at using FlexGet to look at auto downloading torrents via an rss feed.

C# ASP.Net Web Service, JSON and Jqgrid

Posted by beakersoft | Posted in Programming | Posted on 29-07-2011


This week i have been writing a web service in C# that i wanted to use to send data back to a jqrid, and as its been a bit of an uphill battle i thought i’d share what i had found out.

What you Need

First head over to the jqgid page, and download the package.Include all of the base options, and the UI addons to take advantage of the UI theme roller. I would also advise installing the Firebug extension into Firefox, as this can really help you see the interaction between the grid and the web service. Once you have done this, fire up Visual Studio, create a new web project and add a web service (asmx) file, and a web form to your project.

The Web Service

This is where is starts to get interesting, trying to get your web service to return JSON instead of XML. I assume its by design, but even when you change the response format to json as below –

ScriptMethod(ResponseFormat = ResponseFormat.Json)

When you call the web service, it still wraps it in xml tags (for instance, it you return a sting then the response is in a <string> tag), so we need to use a different approach.

Instead of returning a type from your web service, we are going to have no return type, and use the Response.Write functionality to just send text (our json) back to the browser, so in your asmx file you will have a public facing web service that looks something like this –

[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public void GetJSONData(int IDNo){

        string JSONToReturn = GetData(intID);


Now we just need to create our function to give us the data back, formated as a JSON string, that we can feed back into our jQgrid. Before you start creating your JSON, its a good idea to have a validitor to hand, that way you should be able to catch any issues before you try and create your grid. I used one at but there are quite a few out there.

Next, we are going to create a very simple class for holding our data in ready to parse into JSON. My example is based on the information you want being in a SQL DB but it could be comming from anywhere. Anyway, here’s the class –

private class MyJSONInfo
public MyJSONInfo()
        int ID = 0;
        string UserName = string.Empty;
        string EmailAddress = string.Empty;
        string WelcomeMessage = string.Empty;

        public int ID { get; set; }
        public string UserName { get; set; }
        public string EmailAddress { get; set; }
        public string WelcomeMessage { get; set; }

Now we have a class to hold our data in, we need to popluate it. All we are going to do now is run an sql command to get our data, then put that data into our MyJSONInfo class

SqlConnection myConnection = new SqlConnection("[YOUR DB CONNECTION]");
catch (Exception e)
Context.Response.Write("Problem opening DB - " + e.Message);
SqlCommand myEntriesCmd = new SqlCommand("SELECT * FROM TABLE1", myConnection);
SqlDataReader myEntriesData = myEntriesCmd .ExecuteReader();
int IDCounter = 1;
var EntriesList = new Collection();

//got some data back
if (myEntriesData.HasRows)
while (myEntriesData.Read())
EntriesList.Add(new HubInfo {ID = IDCounter, UserName = myEntriesData["UserName"].ToString().Trim(),
        EmailAddress = myEntriesData["EmailAddress"].ToString().Trim(),
        WelcomeMessage = myEntriesData["WelcomeMessage "].ToString().Trim()});

Almost there now, all we need is information about how rows we are returning, what page number we want to show and how many pages of information we are dealing with. These are all used by the jQgrid to aid its navigation, you will have to work these number out correctly based on your setup. Here we are just going to use dummy numbers.

So, we are going to create an object with these values, along with our MyJSONInfo ready to parse into JSON –

var JsonToReturn = new
        total = 5,           //total number of pages in our grid
        page = 1             //page to show in the grid,
        records = IDCounter, //how many records we are dealing with
        rows = EntriesList,  //our actual data

Now all that is left to do here is parse our variable into a JSON string. To do that we are going to use the Javascript Serilizer that comes with dotnet4, so make sure you include this at the top of your code –

using System.Web.Script.Serialization;

Once we have that in place, we are ready to create our JSON string. Here we do just that, and then flush it out to the browser –

//now serialize the list to json
var jsonSerializer = new JavaScriptSerializer();
string JsonString = jsonSerializer.Serialize(JsonToReturn);

//return the json

At this point when you connect to you invoke your web service you should get JSON formated data back. As I mentioned before i would run this through a validitor before you go any further, as you will probably find you have to clean up some of the text to make it work.

The jQgrid Page

Create a new web page in your project, and add the required javascript and css to your page header so you can use the jQgid, it is important to put them in this order, i’m not sure why but i have had issues in the past with the order of the scripts –

<script type="text/javascript" src="Scripts/jquery-1.5.1.min.js"></script><script type="text/javascript" src="Scripts/grid.locale-en.js"></script>
<script type="text/javascript" src="Scripts/jquery-ui-1.8.14.custom.min.js"></script><script type="text/javascript" src="Scripts/jquery.jqGrid.min.js"></script>

Now you have these, we can create the jQgrid on the page.

<script type="text/javascript">
jQuery(document).ready(function () {
        url: 'HubReader.asmx/GetJSONData
        datatype: 'json',
        contentType: 'application/json; charset=utf-8',
        type: 'POST',
        colNames: ['User', 'Email', 'Message'],
        colModel: [
        { name: 'UserName', index: 'UserName', width: 13, align: "left" },
        { name: 'EmailAddress', index: 'EmailAddress', width: 8, align: "left" },
        { name: 'Started', index: 'WelcomeMessage', width: 11, align: "left" }
        //Map the reader as we are using standard JSON format, not the standard jqgrid format
        jsonReader: {
        page: "page",
        total: "total",
        records: "records",
        root: "rows",
        repeatitems: false,
        id: "ID"
        pager: '#pager1',
        altRows: true,
        rowNum: 15,
        rowList: [15, 30, 45],
        height: 500,
        width: 1050,
        caption: "Search Results",
        viewrecords: true,
        sortorder: "desc",
        jQuery("#datalist").jqGrid('navGrid', '#pager1', { edit: false, add: false, del: false,search: false });

If you have used jQgrid before, most of this should be familiar to you, if not then you should probably have a quick read up on their site about how the grids are created and populated. Once you have built the grid, dont forget to create the elements the grid and pager will live in –

        <table id="datalist" cellpadding="0" cellspacing="0"></table>  
        <div id="pager1"></div> 

Whats happening in the code, well most of the javascript for building the grid is pretty standard, the only bit you might have not seen before is the jsonReader section. As we are not sending the json back in the default format jQgrid understands, we need to tell the grid a little bit about what elements contain what data. This needs to match the info comming out of your JSON. So for example if you have called the section containing the total number of pages TotPages (instead of total like i have) you will have to change the line to –

        total: "TotPages",

more info about the jQgrid data format options can be found at

Also make sure you change your url to point to your web service asmx file.

Hopefully your should now be able to get a jQgrid populating with data from an asmx web service. If your are struggling Firebug is probably your best bet, you can tell right away by switching to its console tag what problems you are having, it will even show you the data your service is sending back.

New software for file housekeeping

Posted by beakersoft | Posted in we3soft | Posted on 30-06-2011


Over at we have recently released some new software, called SpringClean.

It’s a file housekeeping application, with many ways to archive/delete your old files, and advanced features such as searching using a regular expression search, and the ability to update a database with the results of the job

Head over to now to take a look at it. Its only £5 sterling to register its full functionality.

Handling Deleted Users Who own SQL Reporting Subscription

Posted by beakersoft | Posted in SQL Reporting Services | Posted on 01-06-2011


I’ve had an issue this week with some SQL reporting services subscriptions. A user contacted me saying her subscription reports were all failing. At first I assumed there was a problem with the user the report was running as, but it turned out to be something else.

When I tried to change and save the settings on one of the reports, I was presented with this error:

The user or group name ‘Dom\User.Name’ is not recognized. (rsUnknownUserName)

Now, it turned out that the user that had originally create this report subscription had recently been deleted out of the active directory, and there was a lot of reports that this user had created. I had a poke around on the web interface and in the management tools, but i couldn’t see anywhere to change the owner of the subscription.

So, as i’ve had to do in the past I started having a look in the reporting service database. I looked first in the Subscriptions table, and there was an OwnerID field, when I linked this table back to the users table I found it was indeed linked to the old user that had been removed. So, I found a valid user in the table, and ran this SQL to update the Subscriptions table pointing to this user:

UPDATE dbo.Subscriptions SET OwnerID = ‘xxx-xxx-xxx-xxx-New-User’ WHERE OwnerID = ‘xxx-xxx-xxx-xxx-Old-User’

When I opened up the subscription again, the owner was now valid, and I could save the report without the error message. I’m glad i did’nt have to go back to the user and tell them they needed to re-create all the subscriptions!