Archive for Ottobre, 2007

Zip Files (2.0)

Ottobre 25th, 2007

Description: using ICSharpCode.SharpZipLib.Zip library

Link: http://www.codekeep.net/snippets/66104bb1-3798-4d1b-85bc-d4d47ca2a4ee.aspx

/************************************************************************************************
        *                                                                                               *
        *                                           Zip Function                                        *
        *                                                                                               *
        *************************************************************************************************/

        //private bool WriteZipFolder(string strDirectoryPath, string strZipName)
        //{
        //    bool blnIsGood = false;

        //    if (Directory.Exists(strDirectoryPath))
        //    {
        //        try
        //        {
        //            // Depending on the directory this could be very large and would require more attention
        //            // in a commercial package.
        //            string[] filenames = Directory.GetFiles(strDirectoryPath);

        //            // 'using' statements gaurantee the stream is closed properly which is a big source
        //            // of problems otherwise.  Its exception safe as well which is great.
        //            using (ZipOutputStream s = new ZipOutputStream(File.Create(strDirectoryPath + "\\" + strZipName)))
        //            {

        //                s.SetLevel(9); // 0 - store only to 9 - means best compression

        //                byte[] buffer = new byte[4096];

        //                foreach (string file in filenames)
        //                {

        //                    // Using GetFileName makes the result compatible with XP
        //                    // as the resulting path is not absolute.
        //                    ZipEntry entry = new ZipEntry(Path.GetFileName(file));

        //                    // Setup the entry data as required.

        //                    // Crc and size are handled by the library for seakable streams
        //                    // so no need to do them here.

        //                    // Could also use the last write time or similar for the file.
        //                    entry.DateTime = DateTime.Now;
        //                    s.PutNextEntry(entry);

        //                    using (FileStream fs = File.OpenRead(file))
        //                    {

        //                        // Using a fixed size buffer here makes no noticeable difference for output
        //                        // but keeps a lid on memory usage.
        //                        int sourceBytes;
        //                        do
        //                        {
        //                            sourceBytes = fs.Read(buffer, 0, buffer.Length);
        //                            s.Write(buffer, 0, sourceBytes);
        //                        } while (sourceBytes > 0);
        //                    }
        //                }

        //                // Finish/Close arent needed strictly as the using statement does this automatically

        //                // Finish is important to ensure trailing information for a Zip file is appended.  Without this
        //                // the created file would be invalid.
        //                s.Finish();

        //                // Close is important to wrap things up and unlock the file.
        //                s.Close();

        //                blnIsGood = true;
        //            }
        //        }
        //        catch (Exception e)
        //        {
        //            Utility.EmailError(HttpContext.Current, e, "ReverseX11Admin", "");
        //        }
        //    }

        //    return blnIsGood;
        //}

        private bool WriteZipFolder(string strDirectoryPath, string strZipName)
        {
            bool blnIsGood = false;

            string strInnerDir = Path.GetFileName(strDirectoryPath);
            strDirectoryPath = strDirectoryPath.Substring(0, strDirectoryPath.Length - strInnerDir.Length - 1);

            if (Directory.Exists(strDirectoryPath))
            {
                try
                {
                    FastZip fz = new FastZip();
                    fz.CreateZip(ConfigurationManager.AppSettings["ExportParentDir"] + strZipName, strDirectoryPath, true, "");
                    fz = null;

                    blnIsGood = true;
                }
                catch (Exception e)
                {
                    Utility.EmailError(HttpContext.Current, e, "ReverseX11Admin", "");
                }
            }

            return blnIsGood;
        }

WinForms watki2

Ottobre 24th, 2007

Description: Inny sposób do odwolania sie do watku

Link: http://www.codekeep.net/snippets/3b71abcf-d64b-4133-91b5-e7fad806eb35.aspx

form1.Invoke((MethodInvoker)delegate { form1.button1.Text = (i * i).ToString(); });

Inside Camtasia Studio 5: Part 1

Ottobre 24th, 2007

In this article we’re going to look at the major new features of Camtasia Studio 5, including: the streamlined recorder, SmartFocus, ExpressShow, new editing features, features for bloggers, FTP and Screencast, transitions and the project settings. By Nathan Segal. 1024

Page Is Not PostBack

Ottobre 24th, 2007

Description: Page Is Not PostBack

Link: http://www.codekeep.net/snippets/d4b7129d-b8b8-48bc-b3b4-eb425466f87a.aspx

        if (!Page.IsPostBack)
        {
        }

WinForms watki

Ottobre 23rd, 2007

Description: dzialanie wielowatkowe w winforms

Link: http://www.codekeep.net/snippets/ba12c167-7f67-4eed-85c7-ce3ee7d31fc8.aspx

//tworzymy watek do wywolujacej metody
delegate int StringCallback(TreeListViewItem s); //delegat zwraza typ taki jak metoda przyjmuje takie parametry jak metoda

Thread watek = new Thread(new ThreadStart(delegate
			{
				foreach (TreeListViewItem m_Item in bufor)
				{
					if (InvokeRequired)//InvokeRequired info watku glownego
					{
						object[] args = { m_Item };//parametr do przekazania
						Invoke(new StringCallback(OknoView.Items.Add), args);//metoda dow wywolania
					}
				}
			}));
			watek.Start();

Loop through a listbox

Ottobre 23rd, 2007

Description: Loop through a listbox

Link: http://www.codekeep.net/snippets/adb6e4fa-e070-4b9b-8f68-b53b7bba8f7f.aspx

            foreach (DataRowView objDataRowView in bl_MailingManager.LstAnchorFrom.Items) {
                MessageBox.Show("My value: " + objDataRowView["ScheduleID"].ToString());
            }

Windows Messagebox ok/cancel code

Ottobre 23rd, 2007

Description: Windows Messagebox ok/cancel code

Link: http://www.codekeep.net/snippets/c92a0b05-3595-4de8-8058-ff40aa54dfab.aspx

            if (MessageBox.Show("Really delete?", "Confirm Dlete", MessageBoxButtons.OKCancel) == DialogResult.OK) {
                BL_MailingManager bL_MailingManager = new BL_MailingManager(this);
                bL_MailingManager.DeleteAnchorFrom();
                bL_MailingManager.GetDistinctAnchorFrom();
            }

Raise Events

Ottobre 23rd, 2007

Description: To raise events.

Link: http://www.codekeep.net/snippets/55680ffa-35ca-4baa-b567-1500ba06cc76.aspx

using System.Reflection;

Type t     = typeof(Button);
object[] p = new object[1];
p[0]       = EventArgs.Empty;

MethodInfo m = t.GetMethod("OnClick", BindingFlags.NonPublic | BindingFlags.Instance);
m.Invoke(btnButtonYouWantedToSimulateClicking, p);

Get a Selected Feature

Ottobre 22nd, 2007

Description: Sample for finding the (first) selected feature

Link: http://www.codekeep.net/snippets/55f097d7-8346-4824-a87f-278785472ea4.aspx

	private IFeature GetSelectedFeature()
	{
		IActiveView activeView = ..;
		ISelection selection = activeView.Selection;
		IFeature feature = GetSelectedFeature(selection);
		return feature;
	}

	private static IFeature GetSelectedFeature(ISelection selection)
	{
		IEnumFeature enumFeature = selection as IEnumFeature;
		if (enumFeature == null)
			return null;
		else
		{
			enumFeature.Reset();
			return enumFeature.Next();
		}
	}

Using the IActiveViewEvents_SelectionChangedEventHandler

Ottobre 22nd, 2007

Description: Similar to the IEditEvents_OnSelectionChangedEvent Sample is the IActiveViewEvents_SelectionChangedEventHandler

Link: http://www.codekeep.net/snippets/16f3f1e3-5e5d-4d77-a9cb-ec4d67c54c0b.aspx

public class CommandAddWorkItem : ...Command...
{
	private IActiveViewEvents_SelectionChangedEventHandler _activeViewEvents_SelectionChangedEventHandler = null;

	private void WireEvents()
        {
            Map map = .. as Map;
            if (null != map)
            {
                _activeViewEvents_SelectionChangedEventHandler = this.OnSelectionChanged;
                map.SelectionChanged += _activeViewEvents_SelectionChangedEventHandler;
            }

            this.Click += new EventHandler(OnClick);
        }

	private void OnSelectionChanged()
	{
		_msg.Debug("OnSelectionChanged");

		Map map = .. as Map;
		_enabled = (map != null) && (map.SelectionCount > 0)

	private void OnClick(object sender, EventArgs e)
	{
		_msg.Debug("OnClick");
		..blabla..
	}

« Prev - Next »