Wednesday 14 May 2014

[SOLVED]Login failed for user ''. (Microsoft SQL Server, Error: 18456)

Leave a Comment
If you want to try to connect to database using sql authentication and the result is failed due to error code "18456" , here are the solution that you might want to try. I already solved the issue (in my case the problem because of the database did not set to allow sql connection to pass. So the solution is to enable the SQL Server authentication.

Enable SQL Server Authentication 

  1. Login to the SQL Server using windows authentication.
  2. Right click on the SQL Server node >> properties.
  3. Go to Security tab.
  4. Under SQL Authentication choose SQL Server and Windows Authentication mode.
  5. Click Ok Button.
  6. Go to Services . Control Panel >> Administrative tools >> Services >> Find SQLServer instance.
  7. Restart SQL Server instance.
  8. Try to login again using your login information.
  9. Done.


By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

Wednesday 7 May 2014

[SOLVED]Windows Phone 8 - Duplicate Files

Leave a Comment
Windows Phone users around the world have reported that their photos, videos or music automatically create multiple copies of themselves. When you delete a single copy, the rest of them don’t open. There have been ongoing discussions spanning across multiple Windows forums pertaining to the issue, but a real solution hasn’t been found yet.

This bug was probably introduced after GDR 2 update for Windows Phone and usually affects devices with external SD Card support. Some users have suggested that it might be because of the syncing method used (Windows Phone 8 currently uses 4 different ways to import content into the phone: The Windows Phone Modern App, the Windows Phone app for Desktop, using Windows Media Player to sync its contents, or using File Explorer to import items via drag and drop or by copying files). But switching to a different method of syncing doesn’t seem to work for everyone.

Also, re-syncing usually involves emptying the entire media library on the phone, formatting the SD Card and then, and then recopying the music, videos and photos back to the card over again. And even then, you’re not sure the duplication won’t happen again. It’s a lot of time consuming re-work for something that doesn’t even offer a guaranteed fix to the problem.

Well, we have tried out several ways to eliminate duplicates from the Windows Phone library without having to delete an entire media collection. And after a few failed attempts, one of them was successful. It has worked for us and we’re quite certain that it’ll work for you too.

Why does Windows Phone create duplicate media files?

Only the folks over at Microsoft may be able to answer that. We can only make a guess that it occurs when you try to copy / sync an item which is already present on the phone. The phone’s media library is probably maintained by a file, which keeps a tab of all the music, videos and photos present on your SD Card. It would also keep a record of metadata, like song artist, album and so on. In other words, this library file links the information you see on your phone (for example, in the Music + Videos hub) to the files on your SD Card. The file also makes it possible to browse through your media collection without an actual file manager.

When this file gets corrupted, it creates multiple attributes for the same file. So, when you delete a particular copy on your phone, it deletes the actual file present on the SD Card. Now, all the other references to the same file still exist, but the file has been deleted. This might be the reason why the other copies fail to open a file when one copy has been deleted.

SOLUTION

Even though you see multiple copies of media on your phone, Windows Phone does not create multiple copies of files on your Windows Phone. The problem thus lies in a corrupted library file. Unfortunately, there is no way to edit or replace this file. Here, we’ll rather try and let Windows Phone recreate the library from scratch, and this time, without the duplicates.

Note: If you have upgraded to Windows Phone 8.1 and have apps installed on the SD card, the following steps might corrupt these apps. So, make sure you move all your apps to phone memory before proceeding any further. Go to Settings >> Storage Sense >> Tap on SD card >> apps+games. Tap on the selection button at the bottom and check “select all”. Finally, tap on the move button to transfer the apps to phone memory. After successfully completing all the steps, you can transfer the apps back to the SD card if you want to.

Here’s what you should do:

  1. Remove the SD Card from your phone and access it on your computer through a suitable card reader. Once you plug in the card, you should notice only single copies of media files.
  2. Open File Explorer and enable view for hidden files on your computer (Open Folder and Search options >> View tab >> Select Show Hidden files, folders and drives).
  3. Other than media folders (like Music, Videos, etc.), you should see two additional folders labeled WPSystem and System Volume Information on the SD Card. Delete the WPSystem folder. System Volume Information folder can’t be deleted directly on Windows. For deleting it, you need to run a few commands in an elevated (Admin) Command Prompt.Update:  Some of our readers have pointed out that the WPSystem and System Volume Information folders remain hidden even after enabling the “Show Hidden files, folders and drives” option. It appears that you also have to uncheck another option in order to view these folders. Go to Folder and Search options >> View tab >> Uncheck “Hide protected operating system files” option >> Click OK. You will now be able to see both folders in File Explorer.
  4. Note the drive letter assigned to your SD Card.
  5. Go to Start and type “CMD” in the Search box.
  6. Right click on the result (Command Prompt) and choose “Run as Administrator”. Now, execute the following commands one after the other, assuming H is the drive letter assigned to the SD Card:
    - H:
    - attrib -s -h /S /D
    - attrib -r /S /D
    - rd "System Volume Information" /S
    - And enter Y to confirm the delete operation.(Ignore message if the error cannot fine "System Volume Information - because that folder not exist, the action only if you sdcard have System volume information folder)
  7. Now, turn on your Windows Phone and connect it to the computer (without the SD Card).
  8. Navigate to your Phone storage and ensure that there are no references of files from the SD Card. Usually you’d save your photos, videos and music on the SD Card, so the Phone Storage should not display any media file. You may transfer everything from phone storage to sdcard
  9. Disconnect both the phone and SD Card from your computer and insert the card back onto the phone.
  10. Power on the Windows Phone and let it rebuild its library file.


Hopefully, by following these steps, you would have successfully got rid of duplicate file copies. If you found this article helpful, don’t forget to share it with other fellow Windows Phone users.


NOTE : 

  1. Do not copy Camera Roll Folder in memory card using card reader. After rebuild done, then you may copy the Camera Roll Files in the folder using their File Explorer. 
  2. This method sometime work sometime didnt, you need to try and retry again because in my experience the duplicate sometime exist in Folder A, but not Exist in Folder B. If this is the situation(after step 10 done). Then you can plug in USB cable and find the duplicate folder. Delete the folder(Make Sure the Folder cannot see in the photos app in your phone after delete it- If you still see the photo and folder after delete using File explorer, you may wait for a while until the folder dissappear or unplug the cable usb). Then add the folder again using the File Explorer
  3. Make Sure you put files in the correct folder which music files in the Music Folder, image files in Picture Folder and video files in the Videos Folder
  4. This solution works for my Nokia Lumia 1520 . It is soo embarrassing to Microsoft which is cannot build the OS which cannot verify the files before listing the files to end user. Boooo... Windows smart phone is not the "SMART" phone, but "DIFFICULT" phone. End.


Original Article : http://7labs.heypub.com/mobile/fix-media-library-duplicates-windows-phone-8.html


By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

Monday 5 May 2014

SQL view error "more column names specified than columns defined"

Leave a Comment

Error Executing Database Query. [Macromedia][SQLServer JDBC Driver][SQLServer]View or function 'dbo.myviewname' has more column names specified than columns defined.

The error occur because of the original table has changed the column. So that the view definition will affected and whenever you perforl select statement the error will occur.

Solution

Resave the view table and the problem solve.

By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

Saturday 3 May 2014

C# - How to open form in full screen

Leave a Comment
This example shows how to make open windows form full screen of computer.

In this example, i will use F11 as a shortcut key to turn form to full screen.

Step By Step :

  1. Create one windows form project
  2. Add Form 2 in the solution.
  3. Add method to event Key Up in Form 1
  4. Copy code below in Key Up  event method Form 1

The Code

private bool _bFullScreenMode = false;

:
:
:

private void Form1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
	if ( e.KeyData == Keys.F11)
	{
	if (_bFullScreenMode == false)
	    {
		Form2 f = new Form2();
		this.Owner = f;
		this.FormBorderStyle = FormBorderStyle.None;
		this.Left = (Screen.PrimaryScreen.Bounds.Width/2 - this.Width/2);
		this.Top = (Screen.PrimaryScreen.Bounds.Height/2 - this.Height/2);
		f.Show();
		_bFullScreenMode = true;
		f.KeyUp +=new KeyEventHandler(Form1_KeyUp);
            }
            else
            {
		Form f = this.Owner;
		this.Owner = null;
		f.Close();
		this.FormBorderStyle = FormBorderStyle.Sizable;
            }
	}
}

By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

Moving text example in C#

Leave a Comment
This is a example of creating moving text in C#.
In order to do the moving text, you just need timer and label controller/component .


Steps by Step:

  1. Create one windows form project
  2. add one label in the form.
  3. copy and paste code below.
  4. Hit "CTRL + F5" and see what will happen.

The code :

    public partial class Form1 : Form
    {
        private string[] words = new string[3];
        private int i, j;
        public Form1()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if(i.Equals(words[j].Length))
            {               
                label1.Text = "";
                if (j < words.Length - 1)
                {
                    j = j + 1;
                    label1.Text = words[j];
                }
                else
                {
                    j = 0;
                }
                i = 0;
            }
            label1.Text = words[j].Substring(0, i);
            i = i + 1;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            words[0] = "www.developersnote.com";
            words[1] = "www.developersnote.com";
            words[2] = "www.developersnote.com";
            timer1.Start();
        }
    }




By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

CSV Splitter example in VB.NET

Leave a Comment
Hye guys, this is a example of CSV Splitter created from VB.NET language. Since i dont have enough time to explained each code, so i just copy the code here and feel free to ask me in the comment.

Basically this example will split huge .csv file into several file. So that you can open the csv file faster rather than open the huge one.


The Code

Imports System.IO
Imports System.Text

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    <STAThread()> _

    Public Shared Sub Main()
        Application.EnableVisualStyles()
        Application.Run(New Form1)
    End Sub

    Public Sub New()
        MyBase.New()
        'This call is required by the Windows Form Designer.
        InitializeComponent()
        'Add any initialization after the InitializeComponent() call
    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer. 
    'Do not modify it using the code editor.

    Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
    Friend WithEvents btnBrowse As System.Windows.Forms.Button
    Friend WithEvents txtCSV As System.Windows.Forms.TextBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents lblStatus As System.Windows.Forms.Label
    Friend WithEvents btnSplit As System.Windows.Forms.Button
    Friend WithEvents numLinesCount As System.Windows.Forms.NumericUpDown
    Friend WithEvents numMaxFiles As System.Windows.Forms.NumericUpDown
    Friend WithEvents btnAbort As System.Windows.Forms.Button

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.btnSplit = New System.Windows.Forms.Button
        Me.txtCSV = New System.Windows.Forms.TextBox
        Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
        Me.btnBrowse = New System.Windows.Forms.Button
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.lblStatus = New System.Windows.Forms.Label
        Me.numLinesCount = New System.Windows.Forms.NumericUpDown
        Me.numMaxFiles = New System.Windows.Forms.NumericUpDown
        Me.btnAbort = New System.Windows.Forms.Button
        CType(Me.numLinesCount, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.numMaxFiles, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'btnSplit
        '
        Me.btnSplit.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.btnSplit.Location = New System.Drawing.Point(384, 48)
        Me.btnSplit.Name = "btnSplit"
        Me.btnSplit.Size = New System.Drawing.Size(88, 24)
        Me.btnSplit.TabIndex = 0
        Me.btnSplit.Text = "Split Now!"
        '
        'txtCSV
        '
        Me.txtCSV.Location = New System.Drawing.Point(104, 16)
        Me.txtCSV.Name = "txtCSV"
        Me.txtCSV.Size = New System.Drawing.Size(264, 20)
        Me.txtCSV.TabIndex = 1
        Me.txtCSV.Text = "C:\"

        '
        'OpenFileDialog1
        '
        Me.OpenFileDialog1.Title = "Select the CSV file to be splitted"
        '
        'btnBrowse
        '
        Me.btnBrowse.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.btnBrowse.Location = New System.Drawing.Point(384, 16)
        Me.btnBrowse.Name = "btnBrowse"
        Me.btnBrowse.Size = New System.Drawing.Size(88, 24)
        Me.btnBrowse.TabIndex = 4
        Me.btnBrowse.Text = "Browse File"

        '
        'Label1
        '

        Me.Label1.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.Label1.Location = New System.Drawing.Point(8, 16)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(56, 16)
        Me.Label1.TabIndex = 5
        Me.Label1.Text = "CSV File:"

        '
        'Label2
        '
        Me.Label2.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.Label2.Location = New System.Drawing.Point(8, 48)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(96, 16)
        Me.Label2.TabIndex = 6
        Me.Label2.Text = "Number of Lines:"

        '
        'Label3
        '
        Me.Label3.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.Label3.Location = New System.Drawing.Point(8, 80)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(72, 16)
        Me.Label3.TabIndex = 7
        Me.Label3.Text = "Max Pieces:"

        '
        'lblStatus
        '

        Me.lblStatus.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblStatus.Location = New System.Drawing.Point(8, 120)
        Me.lblStatus.Name = "lblStatus"
        Me.lblStatus.Size = New System.Drawing.Size(456, 16)
        Me.lblStatus.TabIndex = 8

        '
        'numLinesCount
        '

        Me.numLinesCount.Increment = New Decimal(New Integer() {1000, 0, 0, 0})
        Me.numLinesCount.Location = New System.Drawing.Point(104, 48)
        Me.numLinesCount.Maximum = New Decimal(New Integer() {10000000, 0, 0, 0})
        Me.numLinesCount.Name = "numLinesCount"
        Me.numLinesCount.Size = New System.Drawing.Size(96, 20)
        Me.numLinesCount.TabIndex = 9
        Me.numLinesCount.Value = New Decimal(New Integer() {50000, 0, 0, 0})

        '
        'numMaxFiles
        '
        Me.numMaxFiles.Location = New System.Drawing.Point(104, 80)
        Me.numMaxFiles.Maximum = New Decimal(New Integer() {100000, 0, 0, 0})
        Me.numMaxFiles.Name = "numMaxFiles"
        Me.numMaxFiles.Size = New System.Drawing.Size(96, 20)
        Me.numMaxFiles.TabIndex = 10

        '
        'btnAbort
        '
        Me.btnAbort.Enabled = False
        Me.btnAbort.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.btnAbort.Location = New System.Drawing.Point(384, 80)
        Me.btnAbort.Name = "btnAbort"
        Me.btnAbort.Size = New System.Drawing.Size(88, 24)
        Me.btnAbort.TabIndex = 11
        Me.btnAbort.Text = "Abort"

        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(490, 160)
        Me.Controls.Add(Me.btnAbort)
        Me.Controls.Add(Me.numMaxFiles)
        Me.Controls.Add(Me.numLinesCount)
        Me.Controls.Add(Me.lblStatus)
        Me.Controls.Add(Me.btnBrowse)
        Me.Controls.Add(Me.txtCSV)
        Me.Controls.Add(Me.btnSplit)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.MaximizeBox = False
        Me.MaximumSize = New System.Drawing.Size(496, 192)
        Me.MinimumSize = New System.Drawing.Size(496, 192)
        Me.Name = "Form1"
        Me.Text = "Form 1"

        CType(Me.numLinesCount, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.numMaxFiles, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
    End Sub
#End Region





    Public Delegate Sub UpdateProgressSub(ByVal CurrentLine As Integer)
    Private _IsAbort As Boolean

    Sub SplitCSV(ByVal FilePath As String, ByVal LineCount As Integer, ByVal MaxOutputFile As Integer, ByVal Status As UpdateProgressSub, ByRef IsAbort As Boolean)

        ' Validate first
        If LineCount < 100 Then Throw New Exception("Number of lines must be more than 100.")
        ' Open the csv file for reading
        Dim Reader As New IO.StreamReader(FilePath)

        ' Create the output directory
        Dim OutputFolder As String = FilePath & "_Pieces"

        If Directory.Exists(FilePath) = False Then
            Directory.CreateDirectory(OutputFolder)
        End If

        ' Read the csv column's header
        Dim strHeader As String = Reader.ReadLine

        ' Start splitting
        Dim FileIndex As Integer

        Do
            ' Update progress
            FileIndex += 1
            If Not Status Is Nothing Then
                Status.Invoke((FileIndex - 1) * LineCount)
            End If

            ' Check if the number of splitted files doesn't exceed the limit
            If (MaxOutputFile < FileIndex) And (MaxOutputFile > 0) Then Exit Do

            ' Create new file to store a piece of the csv file
            Dim PiecePath As String = OutputFolder & "\" & Path.GetFileNameWithoutExtension(FilePath) & "_" & FileIndex & Path.GetExtension(FilePath)

            Dim Writer As New StreamWriter(PiecePath, False)
            Writer.AutoFlush = False
            Writer.WriteLine(strHeader)

            ' Read and writes precise number of rows
            For i As Integer = 1 To LineCount
                Dim s As String = Reader.ReadLine()
                If s <> Nothing And _IsAbort = False Then
                    Writer.WriteLine(s)
                Else
                    Writer.Flush()
                    Writer.Close()
                    Exit Do
                End If
            Next

            ' Flush and close the splitted file
            Writer.Flush()
            Writer.Close()
        Loop
        Reader.Close()
    End Sub

    Private Sub btnSplit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSplit.Click
        Dim th As New Threading.Thread(AddressOf SplitIt)
        th.Start()
    End Sub

    Sub SplitIt()
        btnSplit.Enabled = False
        btnAbort.Enabled = True
        Try

            SplitCSV(txtCSV.Text, numLinesCount.Value, numMaxFiles.Value, AddressOf UpdateProgress, _IsAbort)

            If Not _IsAbort Then
                MsgBox("Completed Successfully!", MsgBoxStyle.Information)
            Else

                _IsAbort = False
                MsgBox("Spliting proccess was aborted by user.", MsgBoxStyle.Critical)
            End If



        Catch ex As Exception
            MsgBox("Unable to split the CSV File. Reason: " & ex.Message, MsgBoxStyle.Critical)
        Finally
            btnSplit.Enabled = True
            btnAbort.Enabled = False
        End Try

    End Sub

    Sub UpdateProgress(ByVal CurrentLine As Integer)
        lblStatus.Text = "Aprox. " & CurrentLine.ToString & " lines splitted"
    End Sub


    Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
        If OpenFileDialog1.ShowDialog = DialogResult.OK Then
            txtCSV.Text = OpenFileDialog1.FileName()
        End If
    End Sub

    Private Sub btnAbort_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAbort.Click
        _IsAbort = True
    End Sub

    Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        _IsAbort = True
    End Sub

End Class



By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

CSV Splitter example in C#

Leave a Comment
Hye guys, this is a example of CSV Splitter created from C# language. Since i dont have enough time to explained each code, so i just copy the code here and feel free to ask me in the comment.

Basically this example will split huge .csv file into several file. So that you can open the csv file faster rather than open the huge one.


The Code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.VisualBasic;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Threading;

namespace CSV_Splitter
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public delegate void UpdateProgressSub(int CurrentLine);
        private bool _IsAbort;

        public void SplitCSV(string FilePath,int lineStart, int lineEnd, int LineCount, int MaxOutputFile, UpdateProgressSub Status, ref bool IsAbort)
        {
            // Validate first
            if (LineCount < 100)
                throw new Exception("Number of lines must be more than 100.");            
            // Open the csv file for reading
            System.IO.StreamReader Reader = new System.IO.StreamReader(FilePath);

            // Create the output directory
            string OutputFolder = FilePath + "_Pieces";
            if (Directory.Exists(FilePath) == false)
            {
                Directory.CreateDirectory(OutputFolder);
            }

            // Read the csv column's header
            string strHeader = Reader.ReadLine();

            // Start splitting
            int FileIndex = 0;
            do
            {
                // Update progress
                FileIndex += 1;
                if ((Status != null))
                {
                    Status.Invoke((FileIndex - 1) * LineCount);
                }

                // Check if the number of splitted files doesn't exceed the limit
                if ((MaxOutputFile < FileIndex) && (MaxOutputFile > 0))
                    break; // TODO: might not be correct. Was : Exit Do

                // Create new file to store a piece of the csv file
                string PiecePath = OutputFolder + "\\" + Path.GetFileNameWithoutExtension(FilePath) + "_" + FileIndex + Path.GetExtension(FilePath);
                StreamWriter Writer = new StreamWriter(PiecePath, false);
                Writer.AutoFlush = false;
                Writer.WriteLine(strHeader);
                // Read and writes precise number of rows
                for (int i = 1; i <= LineCount; i++)
                {
                    string s = Reader.ReadLine();
                    if (s != null & _IsAbort == false)
                    {
                        Writer.WriteLine(s);
                    }
                    else
                    {
                        Writer.Flush();
                        Writer.Close();
                        break; // TODO: might not be correct. Was : Exit Do
                    }
                }

                // Flush and close the splitted file
                Writer.Flush();
                Writer.Close();

            } while (true);

            Reader.Close();

        }

        public void UpdateProgress(int CurrentLine)
        {
            lblStatus.Text = "Aprox. " + CurrentLine.ToString() + " lines splitted";
        }

        private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            _IsAbort = true;
        }

        private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
        }

        private void btnSplit_Click_1(object sender, EventArgs e)
        {
            System.Threading.Thread th = new System.Threading.Thread(SplitIt);
            th.Start();
        }

        private void btnBrowse_Click_1(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = openFileDialog1.FileName;
            }
        }

        private void btnAbort_Click_1(object sender, EventArgs e)
        {
            _IsAbort = true;
        }

        public void SplitIt()
        {
            btnSplit.Enabled = false;
            btnAbort.Enabled = true;
            try
            {
                SplitCSV(textBox1.Text,Convert.ToInt32(LinesFrom.Value), Convert.ToInt32(EndLines.Value), Convert.ToInt32(numLinesCount.Value), Convert.ToInt32(numMaxFiles.Value), UpdateProgress, ref _IsAbort);

                if (!_IsAbort)
                {
                    Interaction.MsgBox("Completed Successfully!", MsgBoxStyle.Information,"");
                }
                else
                {
                    _IsAbort = false;
                    Interaction.MsgBox("Spliting proccess was aborted by user.", MsgBoxStyle.Critical,"");

                }
            }
            catch (Exception ex)
            {
                Interaction.MsgBox("Unable to split the CSV File. Reason: " + ex.Message, MsgBoxStyle.Critical,"");
            }
            finally
            {
                btnSplit.Enabled = true;
                btnAbort.Enabled = false;
            }
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Environment.Exit(0);
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }
    }

}


By NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

Subscribe to our newsletter to get the latest updates to your inbox.

Your email address is safe with us!




Founder of developersnote.com, love programming and help others people. Work as Software Developer. Graduated from UiTM and continue study in Software Engineering at UTMSpace. Follow him on Twitter , or Facebook or .



Powered by Blogger.