Twitter <%=Resources.labels.subscribe %>

Silverlight 4 OOB Get Image From Scanner

Here is a simple method you can use to retrieve a JPEG image from a scanner in your Silverlight 4 Out-Of-Browser application:  More »

  • C# IsNumeric Function

    0 Comments | Brent |

    I’m adding this to my code snippets since I use it a lot. It’s a function to check if an object is numeric in C#. It’s similar to the VB IsNumeric method.
     
    public static bool IsNumeric(object expression)
    {
    if (expression == null)
    return false;

    double number;
    return Double.TryParse(Convert.ToString(expression, CultureInfo.InvariantCulture),
    System.Globalization.NumberStyles.Any, NumberFormatInfo.InvariantInfo, out number);
    }

     

    Tags:

    Permalink |

  • WPF Web Browser - ScriptErrorsSupressed

    0 Comments | Brent |

    The System.Windows.Forms.WebBrowser control has quite a few properties readily available you that aren’t available in it’s big brother – the System.Windows.Controls.WebBrowser. One of them is the ScriptErrorsSupressed property. It’s the property that instructs the web browser control to hide or show an error message box when there are script errors (ex. unhandled javascript errors) on web pages it loads.

    If you have a WPF application that needs a web browser control that can suppresses script errors you have two options. One is to use the System.Windows.Forms.WebBrowser bundled inside a WindowsFormsHost or you can use the WPF web browser - System.Windows.Controls.WebBrowser – and use reflection to suppress script errors. Here is the code to do that:More »

    Tags:

    Permalink |

  • Simple Trick To Publish ANY File Via ClickOnce

    0 Comments | Brent | .NET | WPF

    I recently needed to deploy a WPF application with ClickOnce and have the deployment include an ActiveX DLL.  I couldn’t simply add a reference to the DLL in my solution. When I tried I Visual Studio said:

    Please make sure that the file is accessible, and that it is a valid assembly or COM component.

    Since I couldn’t add it as a reference – it wouldn’t show up in my “Application Files” list (Publish tab of project properties). If it isn’t in the Application Files list then we are unable to include it in the ClickOnce publish.

    To get around this issue there is a simple trick you can do to push your ActiveX DLL (or any file type ) into a ClickOnce publish. Here are the steps:

     

    1. Rename your file to include a .txt extension. It should look something like “myassembly.dll.txt” or [name].[extension].txt’
    2. Add the renamed file to your solution.
    3. In Solution Explorer right-click the file, select properties, and change the Build Action to “Content”
    4. Now go back to Application Files on the Publish tab of the project properties. You should see your file in the list. If they aren’t already set – change the drop downs so that the values are as follows:

     

    • Publish Status – Include (Auto)
    • Download Group - (Required)
    • Hash - (Include)

     

    After those step are complete, you have a small amount of coding to do. We’ll need to rename your file at runtime in order for the file to be usable. To do that we’ll need a bit of code from my last post.

     

    if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed) 
    {
    if (System.Deployment.Application.ApplicationDeployment.CurrentDeployment.IsFirstRun)
    {
    //sneak the dll into the deployment by renaming it
    if (File.Exists("myfile.dll.txt") && !File.Exists("myfile.dll"))
    {
    //rename to dll so it is accessible
    File.Copy("myfile.dll.txt", "myfile.dll");
    }
    }
    }

     

    The code above basically checks to see if it is a ClickOnce deployment and if it is the first time the application has been ran on the current machine, and if so, renames the .txt file you publish with it’s real name so it can now be used as originally intended.

    Using the method outlined in the post, you should be able to easily publish any file type with your ClickOnce deployed application.

    Enjoy!

    Tags: ,

    Permalink |

  • Perform Custom Action - WPF ClickOnce Deployment

    0 Comments | Brent | .NET | WPF

     

    If you’d like your WPF application deployed via ClickOnce to execute a custom action the first time the application is run you can use the following code:

     

    if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
    {
          if (System.Deployment.Application.ApplicationDeployment.CurrentDeployment.IsFirstRun)
          {
                     // do some initialization here
           }
    }

     

    IsNetworkDeployed is a Boolean value indicating whether or not the application has been deployed via ClickOnce. IsFirstRun indicates whether this is the first time the application has been ran on the current machine. Be sure to add a reference to System.Deployment.

    Enjoy!

    Tags: ,

    Permalink |



Intro

My name is Brent Lamborn. I´m 35 years old and I live in Nebraska. I've been coding with the .NET Framework since 2003. I'm a former Marine and I have 5 boys.


View Brent Lamborn's LinkedIn profileView Brent Lamborn's profile

Sponsored By

Categories

Tag Cloud

Blog Roll