c# copy to clipboard with example

[sam_ad id="48" codes="true"]Hi Guys, So lately I've been working on some c# project not big one's because I only like something that has something to do with web. So in c# my projects are more to do with public available APIs. So the project I've been working on now I thought it would be a good Idea to allow user of one of my util to copy a URL to a clipboard. So how? Luckily for me Microsoft .NET framework ships a class called Clipboard How to use this class is what this post is all about. I will be covering the basic usage only. I find it better to show it creating a simple Form application. Lets get started. You can download the sample project files at the end. I created this simple form   This form as you notice does have three actions Copy to clipboard Clear clipboard Launch notepad Clipboard related code that gets executed when you click on Copy to clipboard is shown below [crayon-60027145730e9702240169/] As you can see that we are using Clipboard class and calling a static method called SetText. Above code can be read as copy what I type to clipboard. So when you launch notepad then you can paste your copied text there by pressing CTRL+C To Clear the clipboard, this is how  you do it [crayon-60027145730f0565561344/] Likewise you can add Images, data objects etc to clipboard. You can read more about Clipboard class here http://msdn.microsoft.com/en-us/library/system.windows.forms.clipboard.aspx … [Read more...]

c# number spinner control

[sam_ad id="48" codes="true"]I know this is ridiculous for me posting this but I felt embarrassed when I did not looked at available components In c# the so called Number Spinner  this is how its known in other languages is called NumericUpDown component in c# If you are in design view look for NumericUpDown in your toolbox Simple drag drop to you Form and let it rock'n roll Couple of properties that you would like to set Value = 5; Maximum = 2500; Minimum; Value represents the initial value Maximum and Minimum are self explanatory I hope this helps. … [Read more...]

c# find if value exists in List c sharp

[sam_ad id="48" codes="true"]Hi Guys, Thought that I should share this with you. Many times we will end up using List as our collection holder. And that many time we wonder how to find if a value exists in List. There are many ways you can do it. I'll show you a couple which required less coding. I must admit that I am not a c# pro but learning it on the go for my home made tools which requires me to get my hands dirty with c#. Alright now lets get to the point First we create a List. Below is a basic List object [geshi lang="csharp" nums="1" target="_self" ] [crayon-60027145755ba765525508/] Now lets check if value "hello" exist in lt1or not   [geshi lang="csharp" nums="1" target="_self" ] [crayon-60027145755c4970228815/] I am using LINQ expression above. Above line should leave value "True" in variable "exist" Another way is using function Find on List [geshi lang="csharp" nums="1" target="_self" ] [crayon-60027145755c7176680810/] Above line will leave txt with value hello There are other handy methods to find value in List but I found above the most useful. One liners and does the Job nicely I hope this helps   … [Read more...]

Free rackspace Cloud files windows client

  Hi Guys, How does Rackspace cloud files windows explorer sounds? So as a Fun project I am working on RackSpace Cloud Files Windows Client Tool and version 1.0 (beta) is now available. Its a Simple Windows Client that will do lot of things and you can download it Free of Cost. Documentation or you can say a preview is now available from here  http://jaspreetchahal.org/jcrackspacewindowsclient-help/ Pre-requisite .NET Framework >= 3.5 Download Bug Reports and general Ideas I know there will be few bugs that need to be addressed. My advice is to test this util first to see if it fits with you on test containers. I take no responsibility of any damage that may occur using this util. https://jaspreetchahal.uservoice.com Please prefix [JCRSWC] in your feedback subject.     To support me you can also buy a paid version of this util for $19.99. Everything works the same way except you will get cataloguing support and you won't see Donate buttons in paid version :). That's just to support me. If you want still want paid version for free, that's Ok, Just contact me and I'll give you the download link.   I promise to keep on improving this util if you guys find it useful. Your Feedback is really very important to me.   License ---------------------------- Bottom Line is that I, Jaspreet Chahal will not be responsible for any damage caused directly or inderectly and can not be held liable for anything. You understand that you are Using this util at you own Risk. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction of use, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - You should backlink to http://jaspreetchahal.org if you got a website - You can not distribute, sublicense, and/or … [Read more...]

c# programmatically opening web browser with url

Its simplest thing I've done till date. But you have to know what you need to do.   I read c# books to get to know how to do it but you landed on this page Alright let me show you. Add these few lines to your code, change the URL btw :) [geshi lang="csharp" nums="1" target="_self" ]   [crayon-6002714575891553727683/]   I hope this helps. P.S. I am not a C# expert but know few things :). You should always consult other search results in Google before trying anycode. But you can take my word that above will work.   … [Read more...]

how to: c# prompt window or prompt box in c sharp

Hi Guys, Nowadays I am working on a .NET based project. Even though my area is Web side of things like webservices etc I still have to work with Windows Forms etc. So yesterday I has this problem where I have to open a Prompt Dialog window just like we can do in JavaScript. To my surprise C sharp does not have such control. Now what. I got hold of my colleague and asked him. He said best way is to create a Form with a Textbox and a Button. Grab user input and feed it to main Form. So I end up writing this class which is not very intuitive but does the Trick   [crayon-60027145772bb009793049/] Now from your Main Form call this class as   [crayon-60027145772c1972263121/]     name will now have value grabbed from the Prompt Form. You can do all sort of thing with the Prompt form e.g. centering it, applying new theme etc I hope this helps.     … [Read more...]

c# delete file in directory if exists

The Best way I can tell you is to check if the file is Read-only before you go on deleting it. Lets see how this is done. Say I am going to delete a file here C:\folder\a.txt The code below will check for the file mode and then it will delete it if the file exists [geshi lang="csharp" nums="1" target="_self" ] try { if ((File.GetAttributes("C:\folder\a.txt") & FileAttributes.Hidden) == FileAttributes.readonly) { File.SetAttributes("C:\folder\a.txt", FileAttributes.Normal); if (File.Exists("C:\folder\a.txt")) { File.Delete("C:\folder\a.txt"); } } }catch(Exception e) { Console.WriteLine(e.Message); // check if something went wrong } FYI: To recursively delete a Directory you can do something like this [geshi lang="csharp" nums="1" target="_self" ] Directory.Delete(PATH_TO_DIR,true); // second parameter is setting recursive flag to true [crayon-600271457752d761843092/] Hope this helps … [Read more...]

C# MultiLine strings (c sharp)

Well I lost my way when recently try to assign a value to string variable. This is one mistake that I make again and again. Being doing programming in other languages, those which handle strings differently it is obvious to stuff up simple things when you switch language for your next project. Here is what I tried to allocate [geshi lang="csharp" nums="1" target="_self" ] string myVar = "Correct Usage myapp.exe [-options]"; [crayon-60027145776fe551566537/] This will result in a compiler error. Now because I love an operator that Microsoft introduced as while back which is called @. So sleek yet so powerful when working with string. Now if you prepend the above with @ the error dissappears. [geshi lang="csharp" nums="1" target="_self" ] string myVar = @"Correct Usage myapp.exe [-options]"; You can also do something similar to this. [geshi lang="csharp" nums="1" target="_self" ] string myVar = "Correct Usage"+ "myapp.exe [-options]"; I prefer using @ because it present cleanness to the string and I think the string is more readable. I hope this helps   … [Read more...]

C#: How do you get Application data folder path for current user?

Its really simple actually You should be looking at this Global class [geshi lang="csharp" nums="1" target="_self" ] Environment [crayon-60027145778b0354863450/] This class has a function called called GetFolderPath. This is how you use it [geshi lang="csharp" nums="1" target="_self" ] Environment.GetFolderPath(); This method takes Environment.SpecialFolder (Type Enum) as an argument. So for final solution you should be looking at this [geshi lang="csharp" nums="1" target="_self" ] Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData); // thus if you want to read a file from this folder you can initialize a variable as var fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "YOUR_FILE_NAME.EXTENSION") MSDN Resources: Environment.SpecialFoler Enumeration is explained here http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx Environment.GetFolderPath Method is explained here http://msdn.microsoft.com/en-us/library/dd992682.aspx P.S.: I am not a C# expert but occasional C# user for smaller projects. I hope this helps       … [Read more...]