Issues with WPF Drag & Drop in Vista / Windows 7

by robotix1986 25. October 2009 21:41

Hi Folks,

This time, back to WPF. I thought of using the drag & drop functionality in WPF. Just some experiments. Half-way through my coding. A DCR you may say.
I went through the Forbidden IconWPF documentation on MSDN, which seemed pretty straight-forward. I added the AllowDrop="True" tag to a ListView control for which I needed this feature. And I Compiled it.
So far so good. Then I tried dropping a file onto the ListView. However, no luck. All I got is the forbidden icon.

Hmm. Maybe it's some logic in my code that's preventing this from happening. I created a sample app with just the single ListBox. Still the same result.
I searched a couple of blogs. All examples were either similar or exactly the same as mine.
http://www.kirupa.com/blend_wpf/drag_drop_files_wpf_pg1.htm
http://www.codeproject.com/KB/WPF/WPF_Drag_And_Drop_Sample.aspx
http://msdn.microsoft.com/en-us/library/bb295243.aspx

Solution

Next, I started searching for issues with WPF drag & drop. No luck here either. Finally, found that Vista has an issue... or a "By Design" thing... which says that "Vista prevents lower security applications from giving data (and potentially hurting) higher level applications". It seems that same is the case with Windows 7.

Bingo... I was running VS and debugging as an Administrator. Running the application outside of VS makes it work perfectly fine. And thus I found my solution and my app it's drag & drop feature.

Till my next post

Regards,
AlD

Tags: , ,

.NET

Powershell - creating files and folders programmatically

by robotix1986 22. October 2009 12:24

To create a file programmatically we can use the below command: -

new-item -path c:\Test -name MyTestFile.txt -type "file" -value "This is a Test File with sample contents."

the above command creates a file "MyTestFile.txt" within the "C:\Test" directory with the given contents.

To create a folder, we can use the below command: -

new-item -path D:\MyAlreadyExistingFolder -name MyNewFolder -type directory

This command creates a folder named "MyNewFolder" within the "MyAlreadyExistingFolder" folder.

The essential thing to be noted in the above commands is the 'new-item' cmdlet. For more details and additional usage of this command visit this page.

Till my next post

Regards,
AlD

Tags:

Creating your own Visual Studio code snippets

by robotix1986 19. July 2009 11:44

So just some time back I got thinking... everytime I start reading mails in the C# discussion alias at my company or Eric Lippert's explanations in them... the first thing I do is open up my very extensively used Console Application project in Visual Studio, comment out the existing main function for future reference and start writing a new one... and it is kind of a pain to do this.. so I thought that it's time to get it automated.. so I wrote a snippet to do that for me.

Below is the code for that: -

<?

xml version="1.0" encoding="utf-8" ?>
<
CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <
CodeSnippet Format="1.0.0">
        <
Header>
            <
Title>mainfn</Title>
            <
Shortcut>mainfn</Shortcut>
            <
Description>Code snippet for 'Main' function</Description>
            <
Author>Alvaro Rahul Dias</Author>
            <
SnippetTypes>
                <
SnippetType>Expansion</SnippetType>
                <
SnippetType>SurroundsWith</SnippetType>
            </
SnippetTypes>
        </
Header>
        <
Snippet>
            <
Declarations>
                <
Literal>
                    <
ID>expression</ID>
                    <
ToolTip>Code in main method</ToolTip>
                    <
Default>Console.WriteLine("Hello World!");</Default>
                </
Literal>
            </
Declarations>
            <
Code Language="csharp"><![CDATA[ public class MyClass
            {
                public static void Main()
                {
                    $expression$
                    $selected$ $end$
                }
            }
]]>
            </
Code>
        </
Snippet>
    </
CodeSnippet>
</
CodeSnippets>


Most of the fields above are self explanatory. I'll explain a few important ones.
The <Shortcut> tag specifies what you need to type in VS to use this snippet.
<SnippetTypes> - where you can use this snippet, Expansion, Surround With or both.
<Code Language="csharp"> - the actual code to be inserted

Interesting thing to note is that all the variable items are marked with $ signs. The $selected$ attribute signifies where the selected code should go in case you use this code as a sorround with snippet.
The $end$ attribute signifies where the cursor should go once you're finished with the snippet.

Hope the above helps in your coding adventures.


Regards,
AlD

Tags: , ,

.NET

Programmatically adding FlatFileDestination to a SSIS Package

by robotix1986 16. July 2009 16:02

Well this entry is all code.. no explanations... you figure it out yourselves

Microsoft.SqlServer.Dts.Runtime.

Package package = new Microsoft.SqlServer.Dts.Runtime.Package();

Executable executable = package.Executables.Add("STOCK:PipelineTask");
Microsoft.SqlServer.Dts.Runtime.
TaskHost thMainPipe = executable as Microsoft.SqlServer.Dts.Runtime.TaskHost
;
MainPipe dataFlowTask = thMainPipe.InnerObject as MainPipe;


// Add a flat file destination component to the data flow task
IDTSComponentMetaData100
destinationComponent = dataFlowTask.ComponentMetaDataCollection.New();
destinationComponent.Name =
"FlatFileDestination"
;
destinationComponent.ComponentClassID =
"DTSAdapter.FlatFileDestination"
;

// Get the design time instance of the flat file destination component.
CManagedComponentWrapper
destinationInstance = destinationComponent.Instantiate();

// Initialize the flat file destination component
destinationInstance.ProvideComponentProperties();

// Configure the flat file destination component to use the Flat File connection manager
destinationComponent.RuntimeConnectionCollection[0].ConnectionManager = DtsConvert
.GetExtendedInterface(destinationConnection);
destinationComponent.RuntimeConnectionCollection[0].ConnectionManagerID = destinationConnection.ID;

// Configure the custom properties of the Flat File destination component
destinationInstance.SetComponentProperty("Header", ""
);
destinationInstance.SetComponentProperty(
"Overwrite", true
);

// Reinitialize the metadata.
destinationInstance.AcquireConnections(null
);
destinationInstance.ReinitializeMetaData();
destinationInstance.ReleaseConnections();

// ADD OTHER TASKS HERE

Hope this helps.

Regards,
AlD

 

 

Tags: , ,

.NET | Software

Programmatically creating SSIS Packages

by robotix1986 22. June 2009 20:43

Hi g33ks,

The SSIS object model gives us the flexibility of dynamically creating SSIS packages and running them. One major boon with this is that instead of doing column mapping of DFTs at design time, we can do this at runtime and have the mapping information in the metadata.

Today instead of posting some sample code for some basic stuff in creating SSIS packages, I thought that it would make more sense to just post some links which have sample code for various kinds of basic tasks in SSIS. So here goes.

Adding connections - http://msdn.microsoft.com/en-us/library/ms136093.aspx

Variables - http://msdn.microsoft.com/en-us/library/ms136082.aspx

Adding a Data Flow Task - http://msdn.microsoft.com/en-us/library/ms135997.aspx

Adding Data Flow Components - http://msdn.microsoft.com/en-us/library/ms135932.aspx

Connecting Data Flow Components - http://msdn.microsoft.com/en-us/library/ms136086.aspx

ADO.NET Source - http://blogs.msdn.com/mattm/archive/2008/12/30/api-sample-ado-net-source.aspx

OLEDB Source & Destination - http://blogs.msdn.com/mattm/archive/2008/12/30/api-sample-oledb-source-and-oledb-destination.aspx

Saving a Package - http://msdn.microsoft.com/en-us/library/ms403347.aspx


More elaborate samples to come soon. Till
then, Adeus.

Regards,
AlD

Tags: ,

Software

Internet Explorer 8 Addons – Part 1: Accelerators

by robotix1986 19. June 2009 19:26

Hi Folks,

was just trying out some of the accelerators that are available for IE8. I got thinking, why not make a custom one of my own… was it going to be rocket science or child’s play… i was bout to find out… well it turns out that it ain’t that complex.. in fact it is pretty straight-forward.

it involves basically just two main steps: -

  1. Create the XML file known as the Service XML. Refer to the sample below. 

    <?xml version="1.0" encoding="utf-8" ?>
    <openServiceDescription xmlns="http://www.microsoft.com/schemas/openservicedescription/1.0">
      <homepageUrl>http://www.robotix1986.com/code/IE8Add-ons.aspx</homepageUrl>
      <display>
        <name>Sample Search Accelerator</name>
        <description>get a list of Friends and Family Birthdays</description>
      </display>
      <activity category="Search">
        <activityAction context="selection">
          <preview method="get" action="http://www.robotix1986.com/code/SampleSearch.aspx">
            <parameter name="query" value="{selection}" type="text"></parameter>
          </preview>
          <execute method="get" action="http://www.robotix1986.com/code/SampleSearch.aspx">
            <parameter name="query" value="{selection}" type="text"></parameter>
          </execute>
        </activityAction>
      </activity>
    </openServiceDescription>

    As you can see above, the xml is pretty much self explanatory. It gives basic information pertaining to the accelerator.

  2. Now that you have this XML ready all you need to do is create a page from where you can add this accelerator to your browser. All you need on the page is a button which makes a simple call. Sample is given below.

    <
    button onclick="window.external.AddService('http://www.robotix1986.com/code/Data/SampleAccelerator.xml');"> Add SampleAccelerator to your browser</button>

Happy Exploring!!

Regards,
AlD

Tags: ,

Software

Once I was a College Student

by robotix1986 2. June 2009 11:16

So there I was, sitting at my desk staring at the computer screen working on VS 2010 and exploring a bit of F#. I just sat back and started reflecting on my college days and the interviewing season in the 7th semester. All of us, revising all our technical knowledge, solving puzzles and complex analytical problems.
As I think about it now, I think that those problems (especially the programming ones) were pretty easy ones, but in that period, preparing for your first tryst with the world outside, its a huge thing. So, feeling a little nostalgic, I thought I’ll rewrite some of those programs in C# this time.

1.  How to swap two numbers without using a third variable.
    public class SwapperClass
    {
        public static void Main()
        {
            int number1 = 10;
            int number2 = 20;

           
Console.WriteLine("a = {0}, b={1}", number1, number2);

           
Swap(ref number1, ref number2);

           
Console.WriteLine("a = {0}, b={1}", number1, number2);
            Console.ReadLine();
        }
 
        public static void Swap(ref int a, ref int b)
        {
            a = a + b;
            b = a - b;
            a = a - b;
        }
    }

2.  How to find out whether a number is a power of 2 or not in O(1) or without using any loops
   
public class PowerOfTwo
    {
        public static void Main()
        {
            Console.WriteLine(IsPowerOfTwo(4));
            Console.ReadKey();
        }
 
        public static bool IsPowerOfTwo(int a)
        {
            return (a != 0 && (a & (a - 1)) == 0);
        }
    }

Till my next post,

Adeus,
Alvaro

Tags: , ,

Software

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen

About robotix1986

Yet another software developer in the software industry writing some kewl code and exploring new technologies when not doing the routine work stuff.

RecentComments

Comment RSS
Software Blogs - BlogCatalog Blog Directory