Popular Posts

Thursday, July 14, 2016

SAP crystal reports Installation Error 2753

When attempting to install SAP Crystal Reports for Visual Studio 2012 , the installation fails with the following message:

Error 2753. The File "agent.exe.6ED28686_7B19_420C_B255_5B6C1BD2C705" is not marked for installation.

this error because of the FLEXnet Connect component.  there are bug in FLEXnet component.

Here are the steps to resolve the issue:

1. Uninstall SAP Crystal Reports. 

2. Download and run the FLEXnet Connect Uninstall utility from 

3. Delete (or move to a backup directory) the following directories:
   C:\Documents and Settings\All Users\Application Data\Macrovision\FLEXnet Connect
   C:\Documents and Settings\All Users\Application Data\FLEXnet
 4. Reinstall SAP Crystal Reports.


Thursday, September 24, 2015

Thread in c#

Below is the code to use thread in c# and WPF for responsive UI.

void Main()
{
 ThreadStart ts = new ThreadStart(Test);
            Thread th = new Thread(ts);
            th.IsBackground = true;
            th.Priority = ThreadPriority.Lowest;
            th.Start();
}
void Test()
{
//TODO lengthy work
}

Wednesday, September 23, 2015

Freeze GridView Header While Scrolling

First create a CSS class as following.

.HeaderFreez { position:relative ; top:expression(this.offsetParent.scrollTop); z-index: 10; } and Set Gridview’s HeaderStyle CssClass as below. CssClass="HeaderFreez"

Thursday, September 17, 2015

Upload file using FTP

Due to security reason we can't upload file to server using HTTP, so best solution is to use FTP for the same.

Below is the complete solution for upload file to server using FTP. keep in mind user those are using should be write permission on the upload folder.

HTML--

 <form id="form1" runat="server">
        <div style="height:100px; border:medium solid #808080; margin:10px; padding:10px;">
            <asp:FileUpload ID="fileUpload" runat="server" />
            <asp:Button ID="Button1" Text="Upload" Width="100px" Height="30px" runat="server" OnClick="cpUploads" />
            <hr />
            <asp:Label ID="lblMessage" runat="server" />
        </div>
    </form>


CS Code--
protected void cpUploads(object sender, EventArgs e)
        {
            string cpPlusServerIP = "ftp.YOURSITE.com/";
            string serverUserName = "USERNAME";
            string serverUserPassword = "PASSWORD";
            byte[] fileBytes = null;
            FtpWebRequest cpFTPRequest;
            using (StreamReader fileStream = new StreamReader(fileUpload.PostedFile.InputStream))
            {
                fileBytes = Encoding.UTF8.GetBytes(fileStream.ReadToEnd());
                fileStream.Close();
            }
            cpFTPRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + cpPlusServerIP + "/" + fileUpload.FileName));
            cpFTPRequest.Credentials = new NetworkCredential(serverUserName, serverUserPassword);
            cpFTPRequest.KeepAlive = false;
            cpFTPRequest.UseBinary = true;
            cpFTPRequest.ContentLength = fileUpload.FileName.Length;
            cpFTPRequest.Method = WebRequestMethods.Ftp.UploadFile;
            try
            {
                using (Stream cpRequestStream = cpFTPRequest.GetRequestStream())
                {
                    cpRequestStream.Write(fileBytes, 0, fileBytes.Length);
                    cpRequestStream.Close();
                }
                lblMessage.Text = "File Uploaded";
            }
            catch (Exception exception)
            {
                //TODO
                //Redirect to error handler page with user friendly massege
            }
        }

Tuesday, September 30, 2014

How to filter number in textbox



Below is the complete solution for accept only number and decimal by Textbox  in wpf.


First have create a DP.

 public static class TextBoxFilter
    {
        private static readonly List<Key> _controlKeys = new List<Key>
                                                            {
                                                             
                                                                Key.End,
                                                                Key.Enter,
                                                                Key.Escape,
                                                                Key.Home,
                                                                Key.Insert,
                                                                Key.Left,
                                                                Key.PageDown,
                                                                Key.PageUp,
                                                                Key.Back,
                                                                Key.CapsLock,
                                                                Key.LeftCtrl,
                                                                Key.RightCtrl,
                                                                Key.Down,
                                                                Key.Right,
                                                                Key.LeftShift,
                                                                Key.RightShift,
                                                                Key.Tab,
                                                                Key.Up,
                                                             
                                                           
                                                            };

        private static bool _IsDigit(Key key)
        {
            bool shift = (Keyboard.Modifiers & ModifierKeys.Shift) != 0;
            bool retValue;
            if (key >= Key.D0 && key <= Key.D9 && !shift || key == Key.OemPeriod)
            {
             
                retValue = true;
            }
            else
            {
                retValue = key >= Key.NumPad0 && key <= Key.NumPad9;
            }
            return retValue;
        }

        public static bool GetIsPositiveNumericFilter(DependencyObject src)
        {
            return (bool)src.GetValue(IsPositiveNumericFilterProperty);
        }

        public static void SetIsPositiveNumericFilter(DependencyObject src, bool value)
        {
            src.SetValue(IsPositiveNumericFilterProperty, value);
        }

        public static DependencyProperty IsPositiveNumericFilterProperty =
            DependencyProperty.RegisterAttached(
            "IsPositiveNumericFilter", typeof(bool), typeof(TextBoxFilter),
            new PropertyMetadata(false, IsPositiveNumericFilterChanged));

        public static void IsPositiveNumericFilterChanged
            (DependencyObject src, DependencyPropertyChangedEventArgs args)
        {
            if (src != null && src is TextBox)
            {
                TextBox textBox = src as TextBox;

                if ((bool)args.NewValue)
                {
                    textBox.KeyDown += _TextBoxPositiveNumericKeyDown;
                }
            }
        }

        static void _TextBoxPositiveNumericKeyDown(object sender, KeyEventArgs e)
        {
            bool handled = true;

            if (_controlKeys.Contains(e.Key) || _IsDigit(e.Key))
            {
                handled = false;
            }

            e.Handled = handled;
        }


        //==================On the Change Behaviour

        public static bool GetIsBoundOnChange(DependencyObject src)
        {
            return (bool)src.GetValue(IsBoundOnChangeProperty);
        }

        public static void SetIsBoundOnChange(DependencyObject src, bool value)
        {
            src.SetValue(IsBoundOnChangeProperty, value);
        }

        public static DependencyProperty IsBoundOnChangeProperty =
                    DependencyProperty.RegisterAttached(
            "IsBoundOnChange", typeof(bool), typeof(TextBoxFilter),
            new PropertyMetadata(false, IsBoundOnChangeChanged));

        public static void IsBoundOnChangeChanged(DependencyObject src,
                    DependencyPropertyChangedEventArgs args)
        {
            if (src != null && src is TextBox)
            {
                TextBox textBox = src as TextBox;

                if ((bool)args.NewValue)
                {
                    textBox.TextChanged += _TextBoxTextChanged;
                }
            }
        }

        static void _TextBoxTextChanged(object sender, TextChangedEventArgs e)
        {
            if (sender is TextBox)
            {
                TextBox tb = sender as TextBox;
                BindingExpression binding = tb.GetBindingExpression(TextBox.TextProperty);
                if (binding != null)
                {
                    binding.UpdateSource();
                }
            }
        }
    }


and in XAML.

<TextBox  Name="txtCode"  utility:TextBoxFilter.IsPositiveNumericFilter="True"
                                  utility:TextBoxFilter.IsBoundOnChange="True" />