I had this error “A reference to a higher version or incompatible assembly cannot be added to the project” during my Windows Phone development. I wanted to add some dll’s because there are no nuget packages for smaato, mobfox etc.

http://i.imgur.com/YsNnEWF.png

At first I thought that it was because the dll’s were not build as portable class library. But then I found this other source online which gave me the correct and simple answer: Windows blocks the downloaded dll’s by default. You have to unblock it by going to the properties of the dll.

You can also unblock with powershell by using Unblock-File

So perhaps the dialog of visual studio should tell me that it is impossible to add a reference to a blocked dll.

Good luck!

Pin on pinterest Plus on Googleplus Post on LinkedIn
0 Comments

Here is a small C# code snippet to upload an XML file to an explicit SSL secured FTP server.

When you search nuget for FTP you will get:

image

But which one do you need? Not all of them support FTPS. Well the checkbox gives it away.

If you search for FTPS you will only get these seven results (at this moment):

image

So you need the System.Net.FtpClient from https://netftp.codeplex.com/

And here is the C# code to upload an XDocument to an FTPS server:

private void UploadFile(XDocument xDoc, string filename)
{
    using (FtpClient fc = new FtpClient())
    {
        fc.Credentials = new NetworkCredential(username, password);
        fc.Host = hostname;
        fc.EncryptionMode = FtpEncryptionMode.Explicit;
        fc.ValidateCertificate += fc_ValidateCertificate;
        fc.Connect();
        fc.SetWorkingDirectory("/uploaddir");

        using (var ftpStream = fc.OpenWrite(filename, FtpDataType.Binary))
        {
            if (ftpStream != null)
            {
                xDoc.Save(ftpStream);
                ftpStream.Close();
            }
        }
    }
}

static void fc_ValidateCertificate(FtpClient control, FtpSslValidationEventArgs e)
{
    e.Accept = true;
}

Self signed certificates will otherwise always cause an exception in the ftp libraries because the certificates are not really valid. So you manually have to “validate” it.


Good luck!

Pin on pinterest Plus on Googleplus Post on LinkedIn
0 Comments

I have a table filled with numbers. It is a table with the name numbers and there is only one field named ‘num’ which is an integer (so max value is 2.147.483.647 as seen on MSDN) and the integer is  an identity and unique.

2014-03-05 12_10_47-VM530.ssinternational - dbo.numbers - Microsoft SQL Server Management Studio

The table just contains numbers from 1 until 10.000. I use it to inner join, for instance:

You can have a table with a row: productA is 10 times in stock. You can then inner join the numbers table if you need 10 rows of productA.

select * from products 
inner join numbers on num <= stock

But I only had 10.000 rows in it and encountered a bug in my system because 10.000 was not enough. So I had to increase it. I have found several solutions to create a numbers table. But no snippet to update an existing number table.

So here is my snippet to add additional numbers to your number table:

begin transaction
SET IDENTITY_INSERT [numbers] ON

DECLARE @i INT;
SELECT @i = 10001;
SET NOCOUNT ON
WHILE @i <= 1000000
BEGIN
    INSERT INTO [numbers] (num) VALUES (@i);
    select @i= @i + 1;
end;

SET IDENTITY_INSERT [numbers] OFF
commit
Good luck!
Pin on pinterest Plus on Googleplus Post on LinkedIn

Mads Kristensen created BlogEngine.Net back in 2007. I have tested Dasblog, Wordpress and imageBlogEngine.Net and decided back in 2010 that BlogEngine was my blogging platform of choice. But now in 2014 when responsive design, JSON, HTML5, CSS3 is all well known and supported. I decided to migrate to a new and minimalistic blog platform. It is called MiniBlog and hosted on GitHub. I really like the project’s name and goal. It has less overhead and is really fast! It is based on bootstrap, so responsive by default.

So the requirements for me for my new blogging platform is:

  • .Net C#
  • Bootstrap theme(s)
  • Lightweight
  • Fast
  • Live writer integration
  • RSS feeds (to feed to feedburner)
  • SEO friendly
  • Mobile friendly
  • Azure hosting support

Miniblog has it all. Because I am a lazy bastard programmer, I will call BlogEngine.Net BE and Miniblog MB. Here is how I moved from BE to MB:

1. Forked MB

So that I can contribute and give back to the community. And I can keep my own branch and have a local repository.

2. Moved App_Data posts

Copied all posts from BE to MB. But MB could not found my categories.

3. Formatted BE data for MB

Cloned this formatter to my desktop and uncommented line 17 and commented out line 18 of program.cs and renamed the folder parameter to origin in order to get it to run.

4. Made a custom theme

I have just copied one of the existing theme’s and made adjustments to the CSS (and razor view) You really have all freedom with this blogging platform

5. Moved login credentials

The default login is demo, demo and is stored in your web.config. You can change it, but perhaps accidentally commit it to GitHub, so follow this guide to move it to a separate authentication.config and exclude it in your gitignore.

6. Google Analytics

A plain installation of MiniBlog does not include Google Analytics “integration”. So you manually have to add the tracking code in your custom theme (from step 4) It is a good time to move your old Analytics to the new “universal analytics”. Add the snippet before your </head> tag.

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-XXXXXXX-X');
ga('send', 'pageview');

7. Syntax highlighter

To make the code snippets more readable I use this javascript library to enable syntax highlighting. At first, I took the wrong javascript files from the zip. I found the solution on this post about xregexp not defined.

8. Custom pages

MB is by default just a blogging platform and does not have custom pages for about and/or contact. It is better to add them in the view folder, but then you might have to do some work for better routing, so I added an about.cshtml and contact.cshtml to the root of the project. You can reference the theme’s shared layout there to make it match the rest of the sites layout.

9. Social sharing

This is also related to point 4. It gives visitors the option to share your posts on social networks which can give you a better reach. You can use AddThis or something similar. Or use the official plugins from Facebook and Twitter but that includes more javascript and dom manipulations which cause more load on server and client side. Which gives you less points with Google’s Pagespeed. So I combined the url’s from Hanselman’s post and the icons from Flaticon with the “embed resource as base64” option from web essentials Visual Studio extension.

10. Ads

I included a small javascript reference from developer media (previously lake quincy media) to add some ads to the posts (to try to earn back the money for my hosting bill) and included it in my theme, but I am still looking for the best performing ad dimensions.

11. Url-rewrite

I am using this free extension of IIS to rewrite some url’s and have added this rule to include the www subdomain:

<rule name="Add WWW prefix" stopProcessing="true">
  <match url="(.*)" ignoreCase="true" />
  <conditions>
    <add input="{HTTP_HOST}" pattern="^jphellemons\.nl$" />
  </conditions>
  <action type="Redirect" url="http://www.jphellemons.nl/{R:0}" redirectType="Permanent" />
</rule>
MB has default rules to remove the www subdomain (which I disabled) and has a rule to remove the .aspx which BE has, to get cleaner url’s


Have I missed something? What changes did you make when moving to MiniBlog?

Pin on pinterest Plus on Googleplus Post on LinkedIn
0 Comments
  • Posted in:
  • C#

Dymo has some great label printing hardware and has a nice .Net SDK. It seems that they are moving away from the .Net SDK and more towards the JavaScript SDK. In my situation I wanted to host a small Rest service on a Windows 2012 server so that I can make an Ajax call with jQuery to it to print a label from my web application. So it is a kind of printing proxy with REST. We had previously only Internet explorer support in our web application, so using the Active X component was easy for us. Though it required a client installation and the client to configure the network shared printer.

The strange thing is that this code looks good at first sight. Also if you compare it with the Dymo label code. It even works great on my machine, but when I put it live on our production server it failed. No exception or whatsoever, but it simply said that there is no label writer.

StringBuilder sb = new StringBuilder
var label = DYMO.Label.Framework.Label.Open(System.Web.HttpContext.Current.Server.MapPath(@"~/Content/thelabel.label")); // mvc webapplication
label.SetObjectText("Address", sb.ToString());
label.Print(ConfigurationManager.AppSettings.Get("printername"));
// printername = \\pcname\dymo
  

Even when I list the label printer, it does not show up in the list. Printing with the default label printing software from dymo (version 8.x) works great on my machine and the server, but not by code.

StringBuilder sbPrinters = new StringBuilder();
DYMO.Label.Framework.Printers p = new DYMO.Label.Framework.Printers();
foreach(var printer in p.ToList())
{
    sbPrinters.AppendLine(printer.Name);
    sbPrinters.AppendLine(printer.ModelName);
    sbPrinters.AppendLine(printer.IsConnected.ToString());
    sbPrinters.AppendLine(printer.IsLocal.ToString());
    sbPrinters.AppendLine("-==========-");
}
return sbPrinters.ToString(); // empty...

I have tried an Asp.Net web application 4.5 with WebApi on Windows 2012 and a 4.0 Webforms application on Windows 2003. Both did not work. So what is wrong? I used the build in Visual Studio development server and on both windows servers (2003 and 2012) I used IIS. So that might be the problem. I have heard about Katana and OWIN and started a small test project with this guide. Somehow it works when you are not using IIS! I also tried Asp.Net impersonation in the web.config. Maybe running in full trust works, but I prefer a tiny Windows Service with Owin. So go check out the project page of Katana on codeplex or simply pull down this Nuget package of Microsoft Owin. This Channel9 video of 43 minutes is also a great online source to learn more about the Katana project, OWIN for Asp.Net.

Good luck with the Dymo .Net SDK!

Pin on pinterest Plus on Googleplus Post on LinkedIn