Return to Snippet

Revision: 20053
at November 5, 2009 10:59 by xxtjaxx


Initial Code
using System;                                                                          
using Gtk;                                                                             


public partial class MainWindow: Gtk.Window
{                                          
        public MainWindow (): base (Gtk.WindowType.Toplevel)
        {                                                   
                Build ();                                   
        }                                                   

        protected void OnDeleteEvent (object sender, DeleteEventArgs a)
        {                                                              
                Application.Quit ();                                   
                a.RetVal = true;                                       
        }                                                              

        protected virtual void OnButton1Clicked (object sender, System.EventArgs e)
        {                                                                          
                if(filechooserbutton1.Filename == null) return;                    
                if(entry1.Text == null) return;                                    
                string Src = filechooserbutton1.Filename;                          
                string Dest = entry1.Text;                                         

                System.IO.FileInfo fileInfoSrc = new System.IO.FileInfo(Src);
                System.IO.FileInfo fileInfoDest = new System.IO.FileInfo(Dest);
                if(!fileInfoSrc.Exists) return;                                
                if(fileInfoDest.Exists)                                        
                {                                                              
                        if(movebutton.Active)                                  
                        {                                                      
                                moveOverwrite(Src,Dest);                       
                        }                                                      
                        else                                                   
                        {                                                      
                                copyOverwrite(Src,Dest);                       
                        }                                                      
                }                                                              
                else                                                           
                {                                                              
                        if(movebutton.Active)                                  
                        {                                                      
                                System.IO.File.Move(Src,Dest);                 
                        }                                                      
                        else                                                   
                        {                                                      
                                System.IO.File.Copy(Src,Dest);                 
                        }                                                      
                }                                                              

        }
        void moveOverwrite(string Src,string Dest)
        {                                         
                MessageDialog myMessage = new MessageDialog(this,
                                                                DialogFlags.NoSeparator,
                                                                MessageType.Question,   
                                                                ButtonsType.YesNo,      
                                                                "Do you really want to overwrite : " + 
                                                                Dest +  " ?");                         
                        if((ResponseType)myMessage.Run() == ResponseType.Yes)                          
                        {                                                                              
                                myMessage.Destroy();                                                   
                                System.IO.File.Move(Src,Dest);                                         
                        }                                                                              
                        else                                                                           
                                {myMessage.Destroy();}                                                 
        }
        void copyOverwrite(string Src , string Dest)
        {
                        MessageDialog myMessage = new MessageDialog(this,
                                                                DialogFlags.NoSeparator,
                                                                MessageType.Question,
                                                                ButtonsType.YesNo,
                                                                "Do you really want to overwrite : " +
                                                                Dest +  " ?");
                        if((ResponseType)myMessage.Run() == ResponseType.Yes)
                        {
                                myMessage.Destroy();
                                System.IO.File.Copy(Src,Dest,true);
                        }
                        else
                                {myMessage.Destroy();}

        }
}

Initial URL


Initial Description
This is a small examble on how to move files around in mono and C#.

Initial Title
move files around with mono

Initial Tags


Initial Language
C#