Thursday, October 20, 2011

Enbale FileStream in Sql Server 2008 from Sql Server Management Studio

Use following command to enable filestream in Sql Server.

Use Master
Go
/*0 = FILESTREAM disabled
1 = FILESTREAM for TSQL enabled
2 = FILESTREAM for TSQL and WIN32 streaming enabled*/
EXEC sp_configure 'filestream access level', 2
Go
RECONFIGURE
Go

Monday, August 29, 2011

Resolved Creating Database Diagram In Sql Server 2008 Express

While creating database diagram in Sql Server 2008, we may get the following error.

Database diagram support objects cannot be installed because this database does not have a valid owner. To continue, first use the Files page of the Database Properties dialog box or the ALTER AUTHORIZATION statement to set the database owner to a valid login, then add the database diagram support objects.

We need to following steps to resolve this issue.

In SQL Server Management Studio do the following:

1. Right Click on your database, go to properties
2. Goto the Options Page
3. In the Dropdown at right labeled "Compatibility Level" choose "SQL Server 2005(90)"
4. Goto the Files Page
5. Enter "sa" in the owner textbox.
6. press OK

Steps 2 and 3 are optional. With out these steps also I was able to create DB diagram in Sql Server 2008.

Saturday, June 25, 2011

A stupid bug in IE, that killed our 10 hours.

A stupid bug in IE that killed our 10hours. I told our, that is 5 developers each 2 hours we spent to resolve a issue.

A stylesheet class, because of which IE 8, was automatically redirecting to compatibility mode.

The class is


#BKWords { margin-top: 8px; max-height: 75px; overflow:scroll; }

Above css will not work in IE 8 and will redirect/reload to compatibility mode.

This is an issue in IE8. If you give the style as max-height and overflow scroll, IE8 will redirect automatically to compatibility view. For this we have to give overflow as auto.

Reference:
http://stackoverflow.com/questions/7707/ie8-overflowauto-with-max-height

AnkhSVN add-on a nice Subversion Support for Visual Studio

As all we know SVN is a nice and free source safe tool.

Similarly I was searching a free add in to Integrate SVN and Visual Studio.

AnkhSVN is a nice add on for subversion integration for Visual Studio. Best part is its free. I have seen VisualSVN, but that is licensed. We can visit the following URL and download AnkhSVN.

http://ankhsvn.open.collab.net/

Wednesday, February 9, 2011

What happens when user click .NET assembly (EXE)?

When you double click on a .net .exe assembly

  • Windows' PE (Portable Executable) loader kicks in



  • If you're on a Windows >= Windows XP it will detect that the executable is a managed executable and will forward it to .net by calling _CoreExeMain in mscoree.dll (_CoreDllMain if you double clicked on a managed .dll). It can use the assembly configuration file to know which runtime to use.



  • If you're on Windows < Windows XP, the .exe file contains a small native piece of code that will jump to mscoree.dll's _CoreExeMain or _CoreDllMain.



  • Then mscoree.dll initializes the .net runtime, depending on the global configuration, the assembly configuration file, and what not.



  • Then if it's a .exe, it will JIT compile its entry point method, and start executing it.




  • Reference :
    http://stackoverflow.com/questions/2788270/what-happens-when-user-click-net-assembly-exe

    http://maneshjoseph.blogspot.com/2010/10/what-happens-when-you-click-on-net-exe.html

    Saturday, February 5, 2011

    Get the Image from a Image URL using C#.Net

    Following is code to Get the Image from a Image URL using C#.Net

    private Image ImageFromURL(string Url)
            {
                byte[] imageData = DownloadData(Url);
                ImageDetail imgDetail = new ImageDetail();
                Image img = null;
    
                try
                {
                    MemoryStream stream = new MemoryStream(imageData);
                    img = Image.FromStream(stream);
                    
                   
                    stream.Close();
                }
                catch (Exception)
                {
                }
    
                return img;
            }
    
    private byte[] DownloadData(string Url)
            {
                string empty = string.Empty;
                return DownloadData(Url, out empty);
            }
    
            private byte[] DownloadData(string Url, out string responseUrl)
            {
                byte[] downloadedData = new byte[0];
                try
                {
                    //Get a data stream from the url
                    WebRequest req = WebRequest.Create(Url);
                    WebResponse response = req.GetResponse();
                    Stream stream = response.GetResponseStream();
    
                    responseUrl = response.ResponseUri.ToString();
    
                    //Download in chuncks
                    byte[] buffer = new byte[1024];
    
                    //Get Total Size
                    int dataLength = (int)response.ContentLength;
    
                    //Download to memory
                    //Note: adjust the streams here to download directly to the hard drive
                    MemoryStream memStream = new MemoryStream();
                    while (true)
                    {
                        //Try to read the data
                        int bytesRead = stream.Read(buffer, 0, buffer.Length);
    
                        if (bytesRead == 0)
                        {
                            break;
                        }
                        else
                        {
                            //Write the downloaded data
                            memStream.Write(buffer, 0, bytesRead);
                        }
                    }
    
                    //Convert the downloaded stream to a byte array
                    downloadedData = memStream.ToArray();
    
                    //Clean up
                    stream.Close();
                    memStream.Close();
                }
                catch (Exception)
                {
                    responseUrl = string.Empty;
                    return new byte[0];
                }
    
                return downloadedData;
            }
    
    

    Save Image to Disk using C#.Net

    After lot of search I found the code that saves Image class to harddisk.

    public void SaveImage(Image imgToSave, string FileName)
            {
                //Create empty bitmap image of original size
    
                Bitmap tempBmp = new Bitmap(imgToSave.Width, imgToSave.Height);
    
                Graphics g = Graphics.FromImage(tempBmp);
                //draw the original image on tempBmp
    
                g.DrawImage(imgToSave, 0, 0, imgToSave.Width, imgToSave.Height);
    
    
                //dispose originalImage and Graphics so the file is now free
    
                g.Dispose();
    
                imgToSave.Dispose();
    
                //Save the image file to original location
    
                tempBmp.Save(FileName, System.Drawing.Imaging.ImageFormat.Jpeg);
    
                
            }
    

    Friday, February 4, 2011

    Code For Fetch Images from a URL using C#.net

    public List FetchImages(string Url)
            {
                List imageList = new List();
    
                //Append http:// if necessary
                if (!Url.StartsWith("http://") && !Url.StartsWith("https://"))
                    Url = "http://" + Url;
    
                string responseUrl = string.Empty;
                string htmlData = ASCIIEncoding.ASCII.GetString(DownloadData(Url, out responseUrl));
    
                if (responseUrl != string.Empty)
                    Url = responseUrl;
    
                if (htmlData != string.Empty)
                {
                    string imageHtmlCode = "'); //make sure data will be inside img tag
                        int start = htmlData.IndexOf(imageSrcCode) + imageSrcCode.Length;
                        int end = htmlData.IndexOf('"', start + 1);
    
                        //Extract the line
                        if (end > start && start < brackedEnd)
                        {
                            string loc = htmlData.Substring(start, end - start);
    
                            //Store line
                            imageList.Add(loc);
                        }
    
                        //Move index to next image location
                        if (imageHtmlCode.Length < htmlData.Length)
                            index = htmlData.IndexOf(imageHtmlCode, imageHtmlCode.Length);
                        else
                            index = -1;
                    }
    
                    //Format the image URLs
                    for (int i = 0; i < imageList.Count; i++)
                    {
                        string img = imageList[i];
    
                        string baseUrl = GetBaseURL(Url);
    
                        if ((!img.StartsWith("http://") && !img.StartsWith("https://"))
                            && baseUrl != string.Empty)
                            img = baseUrl + "/" + img.TrimStart('/');
    
                        imageList[i] = img;
                    }
                }
    
                return imageList;
            }
    
       
            private byte[] DownloadData(string Url)
            {
                string empty = string.Empty;
                return DownloadData(Url, out empty);
            }
    
            private byte[] DownloadData(string Url, out string responseUrl)
            {
                byte[] downloadedData = new byte[0];
                try
                {
                    //Get a data stream from the url
                    WebRequest req = WebRequest.Create(Url);
                    WebResponse response = req.GetResponse();
                    Stream stream = response.GetResponseStream();
    
                    responseUrl = response.ResponseUri.ToString();
    
                    //Download in chuncks
                    byte[] buffer = new byte[1024];
    
                    //Get Total Size
                    int dataLength = (int)response.ContentLength;
    
                    //Download to memory
                    //Note: adjust the streams here to download directly to the hard drive
                    MemoryStream memStream = new MemoryStream();
                    while (true)
                    {
                        //Try to read the data
                        int bytesRead = stream.Read(buffer, 0, buffer.Length);
    
                        if (bytesRead == 0)
                        {
                            break;
                        }
                        else
                        {
                            //Write the downloaded data
                            memStream.Write(buffer, 0, bytesRead);
                        }
                    }
    
                    //Convert the downloaded stream to a byte array
                    downloadedData = memStream.ToArray();
    
                    //Clean up
                    stream.Close();
                    memStream.Close();
                }
                catch (Exception)
                {
                    responseUrl = string.Empty;
                    return new byte[0];
                }
    
                return downloadedData;
            }
    

    Code for Image to Byte Array and Byte Array to Image Converter using C#

    Convert Image to byte[] array
    public byte[] imageToByteArray(System.Drawing.Image imageIn)
    {
    MemoryStream ms = new MemoryStream();
    imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Gif);
    return  ms.ToArray();
    }
    
    Convert byte[] array to Image
    public Image byteArrayToImage(byte[] byteArrayIn)
    {
    MemoryStream ms = new MemoryStream(byteArrayIn);
    Image returnImage = Image.FromStream(ms);
    return returnImage;
    }

    Get File Name from URL (C#/.NET)

    string FileName = URL.Substring(URL.LastIndexOf("/") + 1,
    (URL.Length - URL.LastIndexOf("/") - 1));

    Or:

    string fileName = Path.GetFileName(url);

    Ref:

    http://www.thejackol.com/2007/04/10/get-file-name-from-url-cnet/

    Tuesday, January 25, 2011

    Resolved : Debugging Timeout on IIS 7 And Visual Studio

    In IIS 7 go to the Application Pools and select the Advanced Settings for the pool which you process runs in. In the Process Model section you can do one of two things;

    * Set the Ping Enabled property to False. This will stop IIS checking to see if the worker process is still running and keep your process alive permanently (or until you stop your debugged process)
    * If you prefer to allow IIS to continue the monitoring process then change the Ping Maximum Response Timeout value to something larger than 90 seconds (default value).

    Wednesday, January 12, 2011

    Sticky Footer Or Footer At bottom of the web page

    Check the following articles that explain the css hack to keep footer at bottom of the page.
    http://ryanfait.com/resources/footer-stick-to-bottom-of-page/

    http://ryanfait.com/sticky-footer/
    http://www.cssstickyfooter.com/
    http://www.cssstickyfooter.com/using-sticky-footer-code.html

    In case, above links are not working, check below.
    CSS::

    * {
    margin: 0;
    }
    html, body {
    height: 100%;
    }
    .wrapper {
    min-height: 100%;
    height: auto !important;
    height: 100%;
    margin: 0 auto -4em;
    }
    .footer, .push {
    height: 4em;
    }



    <html>
    <head>
    <link rel="stylesheet" href="layout.css" ... />
    </head>
    <body>
    <div class="wrapper">
    <p>Your website content here.</p>
    <div class="push"></div>
    </div>
    <div class="footer">
    <p>Copyright (c) 2008</p>
    </div>
    </body>
    </html>

    Multicolumn Layout With Sticky Footer

    Add clear to the .push div
    .footer, .push {
    clear: both;
    }