Wednesday, August 25, 2010

How to use Jquery in Update panels

I you have this Jquery method to be used

$(function () {

// initialize scrollable
$(".scrollable").scrollable();

});

Then use it inside a function as shown

function BindEvents() {

$(function () {

// initialize scrollable
$(".scrollable").scrollable();

});
}

Then add this script inside the update panel as shown below


<asp:UpdatePanel ID="UpdatePanel9" runat="server">
<ContentTemplate>

<script type="text/javascript">
Sys.Application.add_load(BindEvents);
</script>

//Ur Code Here

</ContentTemplate>
</asp:UpdatePanel>

Sunday, July 25, 2010

Project cannot be opened because its project type (.csproj) is not supported by this version of the application.

To open this project, please use a version that supports this type of project.

Follow the below steps to resolve the above error.
Click Start> All Programs > Visual Studio 2008 > Visual Studio Tools > Click Visual Studio 2008 Command Prompt. Type the below command and press enter.
"devenv.exe /resetskippkgs"
Executing this command should solve your problem.

Thursday, July 22, 2010

How to zip & extract files

 You can use this ZipManager class for zipping files & unzipping.


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.IO;
using ICSharpCode.SharpZipLib.Zip;

namespace WebApplication1.Compress
{
    public class ZipManager
    {
        private static void ZipFiles(string inputFolderPath, string outputPathAndFile, string password)
        {
            ArrayList ar = GenerateFileList(inputFolderPath); // generate file list
            int TrimLength = (Directory.GetParent(inputFolderPath)).ToString().Length;
            // find number of chars to remove     // from orginal file path
            TrimLength += 1; //remove '\'
            FileStream ostream;
            byte[] obuffer;
            string outPath = inputFolderPath + @"\" + outputPathAndFile;
            ZipOutputStream oZipStream = new ZipOutputStream(File.Create(outPath)); // create zip stream
            if (password != null && password != String.Empty)
                oZipStream.Password = password;
            oZipStream.SetLevel(9); // maximum compression
            ZipEntry oZipEntry;
            foreach (string Fil in ar) // for each file, generate a zipentry
            {
                oZipEntry = new ZipEntry(Fil.Remove(0, TrimLength));
                oZipStream.PutNextEntry(oZipEntry);

                if (!Fil.EndsWith(@"/")) // if a file ends with '/' its a directory
                {
                    ostream = File.OpenRead(Fil);
                    obuffer = new byte[ostream.Length];
                    ostream.Read(obuffer, 0, obuffer.Length);
                    oZipStream.Write(obuffer, 0, obuffer.Length);
                }
            }
            oZipStream.Finish();
            oZipStream.Close();
        }//code for zipping files


        private static ArrayList GenerateFileList(string Dir)
        {
            ArrayList fils = new ArrayList();
            bool Empty = true;
            foreach (string file in Directory.GetFiles(Dir)) // add each file in directory
            {
                fils.Add(file);
                Empty = false;
            }

            if (Empty)
            {
                if (Directory.GetDirectories(Dir).Length == 0)
                // if directory is completely empty, add it
                {
                    fils.Add(Dir + @"/");
                }
            }

            foreach (string dirs in Directory.GetDirectories(Dir)) // recursive
            {
                foreach (object obj in GenerateFileList(dirs))
                {
                    fils.Add(obj);
                }
            }
            return fils; // return file list
        }//to get folder files

        private void UnZipFiles(Stream stream, string outputFolder)
        {
            //ZipInputStream s = new ZipInputStream(File.OpenRead(zipPathAndFile));
            ZipInputStream s = new ZipInputStream(stream);

            ZipEntry theEntry;
            string tmpEntry = String.Empty;
            while ((theEntry = s.GetNextEntry()) != null)
            {
                string directoryName = outputFolder;
                string fileName = Path.GetFileName(theEntry.Name);
                // create directory
                if (directoryName != "")
                {
                    Directory.CreateDirectory(directoryName);
                }
                if (fileName != String.Empty)
                {
                    if (theEntry.Name.IndexOf(".ini") < 0)
                    {
                        string fullPath = directoryName + "\\" + theEntry.Name;
                        fullPath = fullPath.Replace("\\ ", "\\");
                        string fullDirPath = Path.GetDirectoryName(fullPath);
                        if (!Directory.Exists(fullDirPath)) Directory.CreateDirectory(fullDirPath);
                        FileStream streamWriter = File.Create(fullPath);
                        int size = 2048;
                        byte[] data = new byte[2048];
                        while (true)
                        {
                            size = s.Read(data, 0, data.Length);
                            if (size > 0)
                            {
                                streamWriter.Write(data, 0, size);
                            }
                            else
                            {
                                break;
                            }
                        }
                        streamWriter.Close();
                    }
                }
            }
            s.Close();
        }

        public static void ZipFiles(string inputFolderPath, string outputFolderPath,string filenameWithExtension, string password)
        {
            if (Directory.Exists(outputFolderPath))//if folder exists delete and recreate it
            {
                DirectoryInfo ifo = new DirectoryInfo(outputFolderPath);
                ifo.Delete(true);
            }

            Directory.CreateDirectory(outputFolderPath);// create folder for lecturer
            ZipFiles(outputFolderPath, filenameWithExtension, password);//zip the crearted folder
        }

        public static void UnZipFiles(string zipPathAndFile, string outputFolder, string password, bool deleteZipFile)
        {
            ZipInputStream s = new ZipInputStream(File.OpenRead(zipPathAndFile));
            if (password != null && password != String.Empty)
                s.Password = password;
            ZipEntry theEntry;
            string tmpEntry = String.Empty;
            while ((theEntry = s.GetNextEntry()) != null)
            {
                string directoryName = outputFolder;
                string fileName = Path.GetFileName(theEntry.Name);
                // create directory
                if (directoryName != "")
                {
                    Directory.CreateDirectory(directoryName);
                }
                if (fileName != String.Empty)
                {
                    if (theEntry.Name.IndexOf(".ini") < 0)
                    {
                        string fullPath = directoryName + "\\" + theEntry.Name;
                        fullPath = fullPath.Replace("\\ ", "\\");
                        string fullDirPath = Path.GetDirectoryName(fullPath);
                        if (!Directory.Exists(fullDirPath)) Directory.CreateDirectory(fullDirPath);
                        FileStream streamWriter = File.Create(fullPath);
                        int size = 2048;
                        byte[] data = new byte[2048];
                        while (true)
                        {
                            size = s.Read(data, 0, data.Length);
                            if (size > 0)
                            {
                                streamWriter.Write(data, 0, size);
                            }
                            else
                            {
                                break;
                            }
                        }
                        streamWriter.Close();
                    }
                }
            }
            s.Close();
            if (deleteZipFile)
                File.Delete(zipPathAndFile);
        }

       
    }
}


For Zipping you can call as shown below.
 Compress.ZipManager.ZipFiles("D:/TestFiles/", "D:/TestBackup/", "Backup1.zip", "");

For unzipping
/*unzipping files*/
Compress.ZipManager.UnZipFiles("D:/TestBackup/Control_demo.zip", "D:/TestBackup/", "sahan", false);

You have to download
ICSharpCode.SharpZipLib

How to uplaod a file to a ftp server

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Net;

namespace WebApplication1.FTP
{
    public class FTPManager
    {
        public string FtpFilePath { get; set; }
        public string FtpInputFilePath { get; set; }
        public string FtpHost { get; set; }
        public string FtpUserName { get; set; }
        public string FtpPAssword { get; set; }

        public void UploadFile(FTPManager fm)
        {
            //try
            //{
            //string ftphost = "203.143.11.98";
            //here correct hostname or IP of the ftp server to be given 

            string ftpfullpath = "ftp://" + fm.FtpHost + fm.FtpFilePath;
            FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
            ftp.Credentials = new NetworkCredential(fm.FtpUserName, fm.FtpPAssword);
            //userid and password for the ftp server to given 

            ftp.KeepAlive = true;
            ftp.UseBinary = true;
            ftp.Method = WebRequestMethods.Ftp.UploadFile;


            FileStream fs = File.OpenRead(fm.FtpInputFilePath);

            int buffLength = 2048;
            byte[] buff = new byte[buffLength];
            int contentLen;



            try
            {
                // Stream to which the file to be upload is written
                Stream strm = ftp.GetRequestStream();

                // Read from the file stream 2kb at a time
                contentLen = fs.Read(buff, 0, buffLength);

                // Till Stream content ends
                while (contentLen != 0)
                {
                    // Write Content from the file stream to the FTP Upload
                    // Stream
                    strm.Write(buff, 0, contentLen);
                    contentLen = fs.Read(buff, 0, buffLength);
                }

                // Close the file stream and the Request Stream
                strm.Close();
                fs.Close();


            }
            catch
            {
                throw new WebException();
            }
        }

        public void UploadFile(FTPManager fm,byte[] buffer)
        {
            try
            {
                //string ftphost = "203.143.11.98";
                //here correct hostname or IP of the ftp server to be given 

                string ftpfullpath = "ftp://" + fm.FtpHost + fm.FtpFilePath;
                FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
                ftp.Credentials = new NetworkCredential(fm.FtpUserName, fm.FtpPAssword);
                //userid and password for the ftp server to given 

                ftp.KeepAlive = true;
                ftp.UseBinary = true;
                ftp.Method = WebRequestMethods.Ftp.UploadFile;
                //FileStream fs = File.OpenRead(fm.FtpInputFilePath);
                //byte[] buffer = new byte[fs.Length];
                //fs.Read(buffer, 0, buffer.Length);
                //fs.Close();
                Stream ftpstream = ftp.GetRequestStream();
                ftpstream.Write(buffer, 0, buffer.Length);
                ftpstream.Close();
            }
            catch
            {
                throw new InvalidDataException();
            }
        }
    }
}


This is the way to use this class

 FTP.FTPManager fm = new FTP.FTPManager();
            fm.FtpUserName = "com";
            fm.FtpPAssword = "Com123$";
            fm.FtpInputFilePath = @"D:/from desktop 2010-06-08.zip";
            fm.FtpFilePath = @"/TestFtp/from desktop 2010-06-08.zip";
            fm.FtpHost = "203.143.11.98";

            if (FileUpload1.HasFile)
            {
                fm.FtpFilePath = @"/TestFtp/"+FileUpload1.PostedFile.FileName;
                fm.UploadFile(fm, FileUpload1.FileBytes);             
            }
            else
                fm.UploadFile(fm);

Tuesday, July 6, 2010

Add/Remove List box control in c#

I found a nice article on Add/Remove List box control in c#...

click Here

C# Class to Get MP3 Header Details

class MP3Header
    {
        // Public variables for storing the information about the MP3
        public int intBitRate;
        public string strFileName;
        public long lngFileSize;
        public int intFrequency;
        public string strMode;
        public int intLength;
        public string strLengthFormatted;

        // Private variables used in the process of reading in the MP3 files
        private ulong bithdr;
        private bool boolVBitRate;
        private int intVFrames;

        public bool ReadMP3Information(string FileName)
        {
            FileStream fs = new FileStream(FileName, FileMode.Open, FileAccess.Read);
            // Set the filename not including the path information
            strFileName = @fs.Name;
            char[] chrSeparators = new char[] { '\\', '/' };
            string[] strSeparator = strFileName.Split(chrSeparators);
            int intUpper = strSeparator.GetUpperBound(0);
            strFileName = strSeparator[intUpper];

            // Replace ' with '' for the SQL INSERT statement
            strFileName = strFileName.Replace("'", "''");

            // Set the file size
            lngFileSize = fs.Length;

            byte[] bytHeader = new byte[4];
            byte[] bytVBitRate = new byte[12];
            int intPos = 0;

            // Keep reading 4 bytes from the header until we know for sure that in
            // fact it's an MP3
            do
            {
                fs.Position = intPos;
                fs.Read(bytHeader, 0, 4);
                intPos++;
                LoadMP3Header(bytHeader);
            }
            while (!IsValidHeader() && (fs.Position != fs.Length));

            // If the current file stream position is equal to the length,
            // that means that we've read the entire file and it's not a valid MP3 file
            if (fs.Position != fs.Length)
            {
                intPos += 3;

                if (getVersionIndex() == 3)    // MPEG Version 1
                {
                    if (getModeIndex() == 3)    // Single Channel
                    {
                        intPos += 17;
                    }
                    else
                    {
                        intPos += 32;
                    }
                }
                else                        // MPEG Version 2.0 or 2.5
                {
                    if (getModeIndex() == 3)    // Single Channel
                    {
                        intPos += 9;
                    }
                    else
                    {
                        intPos += 17;
                    }
                }

                // Check to see if the MP3 has a variable bitrate
                fs.Position = intPos;
                fs.Read(bytVBitRate, 0, 12);
                boolVBitRate = LoadVBRHeader(bytVBitRate);

                // Once the file's read in, then assign the properties of the file to the public variables
                intBitRate = getBitrate();
                intFrequency = getFrequency();
                strMode = getMode();
                intLength = getLengthInSeconds();
                strLengthFormatted = getFormattedLength();
                fs.Close();
                return true;
            }
            return false;
        }

        private void LoadMP3Header(byte[] c)
        {
            // this thing is quite interesting, it works like the following
            // c[0] = 00000011
            // c[1] = 00001100
            // c[2] = 00110000
            // c[3] = 11000000
            // the operator << means that we'll move the bits in that direction
            // 00000011 << 24 = 00000011000000000000000000000000
            // 00001100 << 16 =         000011000000000000000000
            // 00110000 << 24 =                 0011000000000000
            // 11000000       =                         11000000
            //                +_________________________________
            //                  00000011000011000011000011000000
            bithdr = (ulong)(((c[0] & 255) << 24) | ((c[1] & 255) << 16) | ((c[2] & 255) << 8) | ((c[3] & 255)));
        }

        private bool LoadVBRHeader(byte[] inputheader)
        {
            // If it's a variable bitrate MP3, the first 4 bytes will read 'Xing'
            // since they're the ones who added variable bitrate-edness to MP3s
            if (inputheader[0] == 88 && inputheader[1] == 105 &&
                inputheader[2] == 110 && inputheader[3] == 103)
            {
                int flags = (int)(((inputheader[4] & 255) << 24) | ((inputheader[5] & 255) << 16) | ((inputheader[6] & 255) << 8) | ((inputheader[7] & 255)));
                if ((flags & 0x0001) == 1)
                {
                    intVFrames = (int)(((inputheader[8] & 255) << 24) | ((inputheader[9] & 255) << 16) | ((inputheader[10] & 255) << 8) | ((inputheader[11] & 255)));
                    return true;
                }
                else
                {
                    intVFrames = -1;
                    return true;
                }
            }
            return false;
        }

        private bool IsValidHeader()
        {
            return (((getFrameSync() & 2047) == 2047) &&
                    ((getVersionIndex() & 3) != 1) &&
                    ((getLayerIndex() & 3) != 0) &&
                    ((getBitrateIndex() & 15) != 0) &&
                    ((getBitrateIndex() & 15) != 15) &&
                    ((getFrequencyIndex() & 3) != 3) &&
                    ((getEmphasisIndex() & 3) != 2));
        }

        private int getFrameSync()
        {
            return (int)((bithdr >> 21) & 2047);
        }

        private int getVersionIndex()
        {
            return (int)((bithdr >> 19) & 3);
        }

        private int getLayerIndex()
        {
            return (int)((bithdr >> 17) & 3);
        }

        private int getProtectionBit()
        {
            return (int)((bithdr >> 16) & 1);
        }

        private int getBitrateIndex()
        {
            return (int)((bithdr >> 12) & 15);
        }

        private int getFrequencyIndex()
        {
            return (int)((bithdr >> 10) & 3);
        }

        private int getPaddingBit()
        {
            return (int)((bithdr >> 9) & 1);
        }

        private int getPrivateBit()
        {
            return (int)((bithdr >> 8) & 1);
        }

        private int getModeIndex()
        {
            return (int)((bithdr >> 6) & 3);
        }

        private int getModeExtIndex()
        {
            return (int)((bithdr >> 4) & 3);
        }

        private int getCoprightBit()
        {
            return (int)((bithdr >> 3) & 1);
        }

        private int getOrginalBit()
        {
            return (int)((bithdr >> 2) & 1);
        }

        private int getEmphasisIndex()
        {
            return (int)(bithdr & 3);
        }

        private double getVersion()
        {
            double[] table = { 2.5, 0.0, 2.0, 1.0 };
            return table[getVersionIndex()];
        }

        private int getLayer()
        {
            return (int)(4 - getLayerIndex());
        }

        private int getBitrate()
        {
            // If the file has a variable bitrate, then we return an integer average bitrate,
            // otherwise, we use a lookup table to return the bitrate
            if (boolVBitRate)
            {
                double medFrameSize = (double)lngFileSize / (double)getNumberOfFrames();
                return (int)((medFrameSize * (double)getFrequency()) / (1000.0 * ((getLayerIndex() == 3) ? 12.0 : 144.0)));
            }
            else
            {
                int[, ,] table =        {
                                { // MPEG 2 & 2.5
                                    {0,  8, 16, 24, 32, 40, 48, 56, 64, 80, 96,112,128,144,160,0}, // Layer III
                                    {0,  8, 16, 24, 32, 40, 48, 56, 64, 80, 96,112,128,144,160,0}, // Layer II
                                    {0, 32, 48, 56, 64, 80, 96,112,128,144,160,176,192,224,256,0}  // Layer I
                                },
                                { // MPEG 1
                                    {0, 32, 40, 48, 56, 64, 80, 96,112,128,160,192,224,256,320,0}, // Layer III
                                    {0, 32, 48, 56, 64, 80, 96,112,128,160,192,224,256,320,384,0}, // Layer II
                                    {0, 32, 64, 96,128,160,192,224,256,288,320,352,384,416,448,0}  // Layer I
                                }
                                };

                return table[getVersionIndex() & 1, getLayerIndex() - 1, getBitrateIndex()];
            }
        }

        private int getFrequency()
        {
            int[,] table =    {  
                            {32000, 16000,  8000}, // MPEG 2.5
                            {    0,     0,     0}, // reserved
                            {22050, 24000, 16000}, // MPEG 2
                            {44100, 48000, 32000}  // MPEG 1
                        };

            return table[getVersionIndex(), getFrequencyIndex()];
        }

        private string getMode()
        {
            switch (getModeIndex())
            {
                default:
                    return "Stereo";
                case 1:
                    return "Joint Stereo";
                case 2:
                    return "Dual Channel";
                case 3:
                    return "Single Channel";
            }
        }

        private int getLengthInSeconds()
        {
            // "intKilBitFileSize" made by dividing by 1000 in order to match the "Kilobits/second"
            int intKiloBitFileSize = (int)((8 * lngFileSize) / 1000);
            return (int)(intKiloBitFileSize / getBitrate());
        }

        private string getFormattedLength()
        {
            // Complete number of seconds
            int s = getLengthInSeconds();

            // Seconds to display
            int ss = s % 60;

            // Complete number of minutes
            int m = (s - ss) / 60;

            // Minutes to display
            int mm = m % 60;

            // Complete number of hours
            int h = (m - mm) / 60;

            // Make "hh:mm:ss"
            return h.ToString("D2") + ":" + mm.ToString("D2") + ":" + ss.ToString("D2");
        }

        private int getNumberOfFrames()
        {
            // Again, the number of MPEG frames is dependant on whether it's a variable bitrate MP3 or not
            if (!boolVBitRate)
            {
                double medFrameSize = (double)(((getLayerIndex() == 3) ? 12 : 144) * ((1000.0 * (float)getBitrate()) / (float)getFrequency()));
                return (int)(lngFileSize / medFrameSize);
            }
            else
                return intVFrames;
        }
    }

Thursday, June 10, 2010

How to use a FileUpload control Inside of Gridview Which Is Inside of UpdatePanel

 <asp:UpdatePanel ID="UpdatePanel3" runat="server">
<Triggers>
                    <asp:PostBackTrigger ControlID="GrdTopBanners" />
                </Triggers>
      <ContentTemplate>
    <asp:Panel ID="pnlCollapseManageTopBanners" runat="server" Width="100%" CssClass="collapsePanelHeader">
        <asp:Image ID="Image12" runat="server" ImageUrl="~/Images/collapse.gif" />
        <asp:Label ID="Label15" runat="server" Text="Show..." CssClass="collapse"></asp:Label><br />
    </asp:Panel>
    <asp:Panel ID="pnlManageTopBanners" runat="server" Width="100%" CssClass="collapsePanel">
        <asp:GridView ID="GrdTopBanners" runat="server" AutoGenerateColumns="False" DataKeyNames="ImageId"
            OnRowCancelingEdit="GrdTopBanners_RowCancelingEdit" OnRowCommand="GrdTopBanners_RowCommand"
            OnRowDataBound="GrdTopBanners_RowDataBound" OnRowDeleting="GrdTopBanners_RowDeleting"
            OnRowEditing="GrdTopBanners_RowEditing" OnRowUpdating="GrdTopBanners_RowUpdating"
            ShowFooter="True" CssClass="grdStyles"
            OnPageIndexChanging="GrdTopBanners_PageIndexChanging" AllowPaging="True" PageSize="20">
            <Columns>
                <asp:TemplateField HeaderText="Image">
                    <EditItemTemplate>
                        <asp:FileUpload  CssClass="systxtarea_a"   ID="FileUploader" runat="server" />
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:FileUpload  CssClass="systxtarea_a"   ID="FileUploaderNew" runat="server" />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidatorImageUploadAdd" runat="server"
                            ErrorMessage="Please add an image." Text="*" ControlToValidate="FileUploaderNew"
                            ValidationGroup="AddTopBanners">
                        </asp:RequiredFieldValidator>
                        <asp:RegularExpressionValidator ID="RegularExpressionValidatorImageFileType" runat="server"
                            ErrorMessage="Only .gif,.jpeg,.jpg,.bmp formats are allowed." Text="*" ValidationExpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))+(.gif|.jpeg|.jpg|.bmp)$"
                            ControlToValidate="FileUploaderNew" ValidationGroup="AddTopBanners">
                        </asp:RegularExpressionValidator>
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:Image ID="ImgTopBanner" runat="server" Height="50px" Width="50px" ImageUrl='<%# "~/TopBannerLoader.ashx?ImageId=" + Eval("ImageId") %>' />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Edit">
                    <EditItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" ValidationGroup="EditTopBanners"
                            CommandName="Update" Text="Update"></asp:LinkButton>
                         <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
                            Text="Cancel"></asp:LinkButton>
                        <asp:ValidationSummary ID="ValidationSummaryTopBannersEdit" runat="server" CssClass="TextLabels"
                            ShowMessageBox="True" ShowSummary="False" ValidationGroup="EditTopBanners" />
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:LinkButton ID="LinkButton2" runat="server" CommandName="AddNew" ValidationGroup="AddTopBanners"
                            Text="Add New"></asp:LinkButton>
                        <asp:ValidationSummary ID="ValidationSummaryTopBannersAdd" runat="server" CssClass="TextLabels"
                            ShowMessageBox="True" ShowSummary="False" ValidationGroup="AddTopBanners" />
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit"
                            Text="Edit"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Delete">
                    <ItemTemplate>
                        <asp:LinkButton ID="lnkBtnDeleteHotel" runat="server" CausesValidation="False" CommandName="Delete"
                            Text="Delete" OnClientClick="return confirm('Are you certain you want to delete this image?');"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        
        <asp:Label ID="Label16" runat="server" Text="" Visible="false"></asp:Label>
    </asp:Panel>
    <cc1:CollapsiblePanelExtender ID="CollapsiblePanelExtender12" runat="server" TargetControlID="pnlManageTopBanners"
        ExpandControlID="pnlCollapseManageTopBanners" CollapseControlID="pnlCollapseManageTopBanners"
        TextLabelID="Label15" CollapsedText="Manage Top Banners" ExpandedText="Manage Top Banners"
        ImageControlID="Image12" ExpandedImage="~/Images/collapse.gif" CollapsedImage="~/Images/expand.gif"
        Collapsed="True" SuppressPostBack="true">
    </cc1:CollapsiblePanelExtender>
    </ContentTemplate>
          </asp:UpdatePanel>




Add a PostBackTrigger and give the name of the gridview as follows "ControlID="GrdTopBanners""



Monday, June 7, 2010

How to redirect to the login page when using access rules in membership provider

"forms loginUrl="pages/Login.aspx"  name=".ASPXFORMSAUTH"" Add this entry to the Web.Config inside the tag
authentication mode="Forms" .

Thursday, March 25, 2010

Can not restore sql server 2005 Backup

If restoring a .bak file to a new database fails then go to these steps.

Create a new database using this script.

 USE [master]
GO


CREATE DATABASE [Test] ON PRIMARY
( NAME = N'Test', FILENAME = N'C:\Test.mdf' , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
LOG ON
( NAME = N'Test_log', FILENAME = N'C:\Test_log.ldf' , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO

Stop sql server service.

then replace the newly created  .mdf & .ldf files with your older .mdf & .ldf files.

Stop sql server service. 

Refresh  your server tree.


Then you are done...

Tuesday, March 23, 2010

Free Sharepoint Discussion Forums

http://www.sharepointjoel.com/Lists/Posts/Post.aspx?ID=234

http://weblogs.asp.net/soever/archive/2005/03/04/385523.aspx

http://www.datasprings.com/Products/SharePointWebParts/MOSSForums.aspx

http://spforums.codeplex.com/releases/view/53

How to remove the “Title” column from a SharePoint Custom List

Have you asked yourself the question: How do I remove the ‘title column’ from a Sharepoint list? It can be annoying trying to figure out how to remove this column from default lists. Often, site admins want their audiences to click on “New Item” in a Sharepoint list and not have to fill out the default ‘Title’ column content type.


I found a great article while surfing internet.This show you how to remove the
"Title" filed from a custom list

Thursday, February 4, 2010

Change Modified Field of Sahrepoint List Using Object Model in c#

When created items in SharePoint via the object model, you can convert a readonly property of that field to be false in order to allow you to set the value of that field. This is particularly useful for setting created and modified dates (all SharePoint lists retain these).

// get the list and set modified property to allow writing
SPWeb web = new SPSite("http://url/to/web").OpenWeb();
SPList selectedList = web.Lists["listname"];
selectedList.Fields["Modified"].ReadOnlyField = false;
selectedList.Fields["Modified"].Update();


// set the item
SPItem newItem = selectedList.Items[0];
newItem["Modified"] = DateTime.Now;
newItem.Update();

// Set readonly back to true
selectedList.Fields["Modified"].ReadOnlyField = true;
selectedList.Fields["Modified"].Update();

Wednesday, February 3, 2010

Firebug has a lite version that can be used in any browser! Obviously it isn’t as functional as the Firefox plug-in, but it helps out none the less. Some things you are normally used to doing in firebug will not be as easy, such as disabling CSS rules and the handy inspect is less functional.

There are 2 ways to activate Firebug lite:

 1. Including an external JavaScript File
 2. Using a bookmarklet

All you have to do is add the following to your head as a javascript
script type='text/javascript'
src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'

Wednesday, January 6, 2010

How to use decimal in SQL Server

decimal and numeric (Transact-SQL)

Numeric data types that have fixed precision and scale.

decimal[ (p[ , s] )] and numeric[ (p[ , s] )]

Fixed precision and scale numbers. When maximum precision is used, valid values are from - 10^38 +1 through 10^38 - 1. The ISO synonyms for decimal are dec and dec(p, s). numeric is functionally equivalent to decimal.

p (precision)

The maximum total number of decimal digits that can be stored, both to the left and to the right of the decimal point. The precision must be a value from 1 through the maximum precision of 38. The default precision is 18.

s (scale)

The maximum number of decimal digits that can be stored to the right of the decimal point. Scale must be a value from 0 through p. Scale can be specified only if precision is specified. The default scale is 0; therefore, 0 <= s <= p. Maximum storage sizes vary, based on the precision.