RBM Binary Image now displays barcode using Code39

December 11, 2009 · Posted in .NET, ASP.NET, C# · Comment 

RBMBinaryImage Source Code

Introduction

It’s been a while since I lost wrote on my blog yesterday one of my friends was asking me how to display Barcode in asp.net, There is a great open source code written by Bart De Smet which could return a bar code image from a bar code string you could see his article here I have just added to it one small option of whether or not to display the code under the bar code. The library returns an Image I thought of adding the display of bar code from the bar code string value, functionality to RBMBinaryImage would be cool.

RbmBinaryImageBarCode

Bar Code and Binary Image Screen shot

Using the Code

The idea was simple since, the Code39 Library returns already an Image object so I only got it’s bytes and passed it to the ImageContent Property which is then rendered in the image. for more information on how the binary image display works in RBMBinaryImage please visit the post here. Again the usage of the control is still easy, to display the bar code you only need to set the PrintBarcode property to true, and pass the BarCodeValue the bar code as you could see below the DisplayThumbnail Property still is being applied on the bar code.

<Rbm:RbmBinaryImage ID="RbmBinaryImage2" runat="server" PrintBarcode="true"  BarCodeValue='<%# Eval("BarCode") %>' DisplayThumbnail="true"   ThumbnailSize="160"  EmptyImageUrl="images/NoPhoto.JPG" />

I have made one change to the HttpHandler to be with the extension of the .ashx instead of the .rbm extension to be standard

<httpHandlers>
<add verb="GET" path="__RbmImageHandler.ashx" type="RbmControls.RbmImageHandler"/>
</httpHandlers>

Finally, you could find the code here

Uninstall Previous Version of .NET Application Automatically

July 18, 2009 · Posted in .NET, C#, Visual Studio · 2 Comments 
To uninstall a previous version of a .net application automatically while installing the new version. you only need to set the RemovePreviousVersions to true and update the program version. This could be find in the properties of the setup project. check the screenshot below for demonestration uninstall

Deploying Custom Tool using a Setup Project

April 8, 2009 · Posted in .NET, ASP.NET, C# · 3 Comments 

CustomToolDeploymentForVisualStudio.zip

Introduction

Making a custom tool work on the developers machine require several actions like placing keys in the registry and registering your DLL Library using the regasm command. This post will discuss the automation of this procedures using a setup project. for more information on making your own custom tool visit my post Building a Custom Tool Generator For Visual Studio

Using the Code

First add a class in your CustomTool Library Project that inherits from the Installer class in this class override two methods the first is the Install Method the Second is the Uninstall method.

To Get the regasm.exe path you could use the InteropServices.RuntimeEnvironment class to get the runtime directory of the .NET framework. Then you need to get the assembly location. After that you could simply start the process of the regasm and pass to it the /codebase parameter and the path of the library.

public override void Install(System.Collections.IDictionary stateSaver)
{
    base.Install(stateSaver);
    string regasmPath = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() + @"regasm.exe";
    string componentPath = base.GetType().Assembly.Location;
    System.Diagnostics.Process.Start(regasmPath, "/codebase \"" + componentPath + "\"");
}

To uninstall remove the component registeration by the /unregister parameter

public override void Uninstall(System.Collections.IDictionary savedState)
{
    base.Uninstall(savedState);
    string regasmPath = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() + @"regasm.exe";
    string componentPath = base.GetType().Assembly.Location;
    System.Diagnostics.Process.Start(regasmPath, "/unregister \"" + componentPath + "\"");
}

The Setup Project

Now make a new setup project and add the output of the CustomTool Library to it. Then Right Click the setup project and select view then select custom actions.
customactions2
Then Add the CustomTool Project Output to the Install and Uninstall Sections as in the image below.
customtoolsetup
ok now you need to add the registry values right click on the setup project and then View then select Registry To add the Needed Registry Values follow the structure in the figure below.
customtoolregistry

Share your Thoughts

Now all you have to do is just build the setup project :) and you will have a setup deployment for your custom tool.
please share your thoughts and feel free to drop any comments. Hope you enjoy the project.

Building a Custom Tool Generator For Visual Studio

April 7, 2009 · Posted in .NET, C#, Visual Studio · 3 Comments 

CustomToolForVisualStudio.zip
BaseCodeGeneratorWithSite.dll

Introduction

Sometimes you need to generate your own code for some XML Files in your Visual Studio Project or replace the Resource File Generated Code of the Visual Studio with one of your the reason you may want to do this is that you may want to work with a custom resource provider while the generated code in .NET makes the static properties work only with the resource file.

Using the Code

First to do that you need to inherit from the BaseCodeGeneratorWithSite then generate a GUID for it from Tools -> Create Guid -> Then Select the Registry format and copy the guid to mark your class with this GUID Will let the Visual Studio later on know the class it should call. Then place a GUID and a ComVisible attributes on your class.

    [Guid("A2A52B1B-48A1-45af-A30E-8D86E4DE0D79")]
    [ComVisible(true)]
    public class CustomToolGenerator : BaseCodeGeneratorWithSite

Then Override the GenerateCode Method

   protected override byte[] GenerateCode(string inputFileName, string inputFileContent)
   {
        string code = "Generated Code Should Be Placed Here";
        return System.Text.Encoding.ASCII.GetBytes(code);
   }

If you want the namespace that the File is comming from it’s available in the “FileNameSpace” property of the BaseCodeGeneratorWithSite class.

In the AssemblyInfo.cs Class make the Assembly Com Visible by placing the following code in it

[assembly: ComVisible(true)]

Generate a Strong Name Key for your project using the Visual Studio Command Prompt sn -k CustomToolForVisualStudio.snk and bind your project to it- Right Click on the project then select Properties then Select Signing and choose Sign the assembly property and select the Strong Name Key you have just generated

For Registering the Generator in the Visual Studio you need to place a reference to it in the Registry
Visual Studio 2005
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\Generators\
Visual Studio 2008
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\Generators\
These are the sub keys for different languages they are named with their GUID you will go inside them
{164B10B9-B200-11D0-8C61-00A0C91E29D5}: Visual Basic
{E6FDF8B0-F3D1-11D4-8576-0002A516ECE8}: J#
{FAE04EC1-301F-11D3-BF4B-00C04F79EFBC}: C#

Then Create a key with the name of your class and inside it place the following
(Default): String: CustomToolGenerator (name of the custom tool)
CLSID: String: {A2A52B1B-48A1-45af-A30E-8D86E4DE0D79} (Generated Guid)
GeneratesDesignTimeSource: DWORD: 1

Now Register you Assembly using the resgen command in the Visual Studio Command Prompt

regasm /codebase CustomToolForVisualStudio.dll

Using the Custom Tool in Visual Studio

Right Click on a Resource File or XML File and click properties then place in the CustomTool property the value “CustomToolGenerator

The Custom Tool will now generate the code based on the code given in the “GenerateCode
” Method.

Hope you like it :) Please share your thoughts

Control to Display Binary Images in ASP.NET

March 31, 2009 · Posted in .NET, ASP.NET, C# · 63 Comments 
RBMBinaryImage Source Code

Introduction

The RbmBinaryImage control will help you display images directly from your database. You could bind the Image field directly to the ImageContent property, also you could specify whether you want the display to be as a thumbnail or not and provide the thumbnail size.

rbmimagedemo


Using the RbmBinaryImage Control

First you need to add reference to the RbmControls.dll, then place the code below in the system.web section in your web.config

 <httpHandlers>
   <add verb="GET" path="__RbmImageHandler.rbm"
   type="RbmControls.RbmImageHandler" />
  </httpHandlers>
Then in the page you want to use the Control Register it by using

<%@ Register Assembly="RbmControls" Namespace="RbmControls" TagPrefix="Rbm" %>

you could either bind the control directly in the ImageContent Property, Also specify whether to display the image as a thumbnail. and specify an image to display when the ImageContent is empty
an alternative is to do that by code

RbmBinaryImage1.ImageContent = FileUpload1.FileBytes;

Using the Code

rbmbinaryimageclassdiagram1

The RbmBinaryImage Class Inherits from System.Web.UI.WebControls.Image and the functionality of storing and rendering a binary image to it also it adds the ability to generate a thumbnail based on a specified size and caching your image.

The Imagecontent Property Retrieves and store the image bytes in the ViewState also if the DisplayThumbnail property is set to true then it retrieves the thumbnail of the image

public byte[] ImageContent
        {
            get
            {
                byte[] imageBytes = ViewState["ImageContent"] as byte[];
                if (!DisplayThumbnail)
                    return (imageBytes == null) ? null : imageBytes;
                else if (imageBytes != null)
                {
                    byte[] bytes = CreateThumb();
                    return bytes;
                }
                else
                    return null;
            }
            set
            {
                ViewState["ImageContent"] = value;
            }
        }
The OnPreRender Method is used to set the ImageUrl Based on the Property Settings of the Image Control

protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            if (DesignMode)
                return;
            if (ImageContent != null)
            {
                if(string.IsNullOrEmpty(CacheKey))
                    CacheKey = "Rbm" + System.DateTime.Now.Ticks;
                ImageUrl = String.Format("~/__RbmImageHandler.rbm?MimeType={0}&EnableCaching={1}&ImageContent={2}",
                    MimeType, EnableCachinge ? "1" : "0", CacheKey);
                if(this.Context.Cache[CacheKey] == null)
                    this.Context.Cache[CacheKey] = ImageContent;
            }
            else if (ImageUrl == "" || ImageUrl == null)
            {
                ImageUrl = EmptyImageUrl;
            }
        }
In the RbmImageHandler Class in implements the IHttpHandler Interface and override the ProcessRequest method to display the image

public void ProcessRequest(HttpContext context)
        {

            #region Caching Properties
            string cacheKey = context.Request["ImageContent"];
            if (String.IsNullOrEmpty(cacheKey))
                return;
            bool enableCaching = false;
            if (!String.IsNullOrEmpty(context.Request["EnableCaching"]))
                Boolean.TryParse(context.Request["EnableCaching"], out enableCaching);
            #endregion

            #region Image Properties
            string mimeType = context.Request["MimeType"];
            if (string.IsNullOrEmpty(mimeType))
                mimeType = "image/jpeg";
            byte []imageData = context.Cache[cacheKey] as byte[];
            #endregion

            if (!enableCaching)
                context.Cache.Remove(cacheKey);
            context.Response.ContentType = mimeType;
            context.Response.OutputStream.Write(imageData, 0, imageData.Length);
        }

Share your Thoughts

If you liked the control or have any comments on it or features you want to place in it kindly share your thoughts here

Next Page »

























































download movies

ñêà÷àòü ôèëüìû