Tags: , , | Categories: Programlama, Genel, Tanıtım Posted by okutbay on 26.02.2010 16:03 | Yorumlar (0)

There is an open source project to use with your projects. It's easy to use.

dotnetzip.codeplex.com

Let's zip a folder :)

    1 using (ZipFile zip = new ZipFile())

    2 {

    3     zip.AddDirectory("c:\somedirectory");

    4     zip.Comment = "This zip was created at " + System.DateTime.Now.ToString("G");

    5     zip.Save("nameofthezipfile.zip");

    6 }

Happy coding...

Bu yazıyı ilk değerlendiren siz olun

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: , , | Categories: Tip, Programlama, Genel Posted by okutbay on 26.02.2010 11:41 | Yorumlar (0)

You can always write comment to your codes. But comment itself can be outdated and misleads a developer. So writing self-documented codes must our first aim to make our code more maintainable.

In my opinion a big step to achieve self-documented code begins writing if clauses.

If a developer understands if clause, he/she understand purpose of the code block more easily.

But how can we write more readable if clause.

Very easy: Don't write logical comparisons into if clause.

    1 if ((preprocessedFailedEmails.Count > 0) || (failedEmails.Count > 0))

    2 {

    3     //some code

    4 }

Although this is a very simple if clause it's a bit hard to get what is happening there. Let's make it more readable.

    1 bool hasErrors = ((preprocessedFailedEmails.Count > 0) || (failedEmails.Count > 0));

    2 if (hasErrors)

    3 {

    4     //some code

    5 }

Happy coding...

Bu yazıyı ilk değerlendiren siz olun

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: | Categories: IDE, Genel, Tip Posted by okutbay on 25.02.2010 19:08 | Yorumlar (0)

If you're working with lot of projects, or you want to release your DLL to specific location you may need to add some extra actions to to your build.

For example. You have project that uses a DLL of another project of another solution. Sometimes you build your DLL in debug mode, sometimes you build your DLL in release mode. When you build your class library output directory depends on the build mode. Question is: Which DLL will be referenced by your project? To prevent this confusion you can add an copy operation to your post-build events. Then reference the copied DLL.

Here is the sample macro to do this:

cd $(OutDir)
copy $(TargetFileName) D:\Sources\DLLReferences\MyProjectOutpu

Just go to your project properties. Switch "Build Events" tab. Add this sample macro to Post-build event command line. When you build your it will copy result file to specified location.

build-events

Figure 1: Build events window of your project.

post-build-events-command-line-window

Figure 2: A Build event Command line window

You can find a list of macros and their descriptions here:

$(ConfigurationName)

The name of the current project configuration, for example, "Debug|Any CPU".

$(OutDir)

Path to the output file directory, relative to the project directory. This resolves to the value for the Output Directory property. It includes the trailing backslash '\'.

$(DevEnvDir)

The installation directory of Visual Studio 2005 (defined with drive and path); includes the trailing backslash '\'.

$(PlatformName)

The name of the currently targeted platform. For example, "AnyCPU".

$(ProjectDir)

The directory of the project (defined with drive and path); includes the trailing backslash '\'.

$(ProjectPath)

The absolute path name of the project (defined with drive, path, base name, and file extension).

$(ProjectName)

The base name of the project.

$(ProjectFileName)

The file name of the project (defined with base name and file extension).

$(ProjectExt)

The file extension of the project. It includes the '.' before the file extension.

$(SolutionDir)

The directory of the solution (defined with drive and path); includes the trailing backslash '\'.

$(SolutionPath)

The absolute path name of the solution (defined with drive, path, base name, and file extension).

$(SolutionName)

The base name of the solution.

$(SolutionFileName)

The file name of the solution (defined with base name and file extension).

$(SolutionExt)

The file extension of the solution. It includes the '.' before the file extension.

$(TargetDir)

The directory of the primary output file for the build (defined with drive and path). It includes the trailing backslash '\'.

$(TargetPath)

The absolute path name of the primary output file for the build (defined with drive, path, base name, and file extension).

$(TargetName)

The base name of the primary output file for the build.

$(TargetFileName)

The file name of the primary output file for the build (defined as base name and file extension).

$(TargetExt)

The file extension of the primary output file for the build. It includes the '.' before the file extension.

Reference: Pre-build Event/Post-build Event Command Line Dialog Box

Bu yazıyı ilk değerlendiren siz olun

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: , , , , | Categories: Genel, Programlama Posted by okutbay on 23.02.2010 16:49 | Yorumlar (0)

This is sample application to serializes sample object

    1 using System;

    2 using System.Collections.Generic;

    3 using System.Text;

    4 

    5 using System.IO;

    6 using System.Xml.Serialization;

    7 

    8 namespace ConsoleApplication1

    9 {

   10     class Program

   11     {

   12         static void Main(string[] args)

   13         {

   14             SampleObject sampleObject = new SampleObject();

   15             sampleObject.Id = 35;

   16             sampleObject.Name = "Ozan K. BAYRAM";

   17 

   18             XmlSerializer serializer2 = new XmlSerializer(typeof(SampleObject));

   19             MemoryStream ms = new MemoryStream();

   20             XmlSerializerNamespaces xmlSerializerNamespaces = new XmlSerializerNamespaces();

   21             xmlSerializerNamespaces.Add("", ""); //if you want namespace for your XML define here

   22             serializer2.Serialize(ms, sampleObject, xmlSerializerNamespaces);

   23             StringBuilder XMLText = new StringBuilder();

   24             ms.Position = 0;

   25             using (StreamReader Reader = new StreamReader(ms))

   26             {

   27                 XMLText.Append(Reader.ReadToEnd());

   28             }

   29 

   30             string serializedObject = XMLText.ToString();

   31         }

   32     }

   33 }

Output string

xmlserializationoutput

 

Sample class to use

    1 [Serializable]

    2 [System.Xml.Serialization.XmlRoot("sampleobject")]

    3 public class SampleObject

    4 {

    5     [System.Xml.Serialization.XmlAttribute("id")]

    6     public int Id { get; set; }

    7 

    8     [System.Xml.Serialization.XmlElement("name")]

    9     public string Name { get; set; }

   10 }

Bu yazıyı ilk değerlendiren siz olun

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: , | Categories: Tip, SSS (FAQ), Web Uygulaması, Browsers Posted by okutbay on 18.02.2010 13:12 | Yorumlar (0)

If you hava a javascript like this:

    1 <script language="javascript" type="text/javascript">

    2 window.status ='some text';

    3 </script>

You will see firefox is not showing "some text" in the status bar. Too see your text you must enable it from "Advanced Javascript Settings" window.

Enable status bar with FF

 

Happy coding...

Bu yazıyı ilk değerlendiren siz olun

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories: Tip Posted by okutbay on 16.02.2010 15:00 | Yorumlar (0)

Here is a very handy extension method to remove white spaces from strings.

    1 public static string RemoveWhiteSpace(this string TextToRemoveWhiteSpaces)

    2 {

    3     string pattern = "\\s+";

    4     string replacement = " ";

    5     string result = Regex.Replace(TextToRemoveWhiteSpaces, pattern, replacement);

    6     return result;

    7 }

Adapted from http://msdn.microsoft.com/en-us/library/xwewhkd1.aspx

Happy coding.

Bu yazıyı ilk değerlendiren siz olun

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: , , , | Categories: Coding Disaster Posted by okutbay on 16.02.2010 14:27 | Yorumlar (0)

When you are coding don't forget to use your brain. Always ask yourself. "Is there another way to do this?", "What am i doing here?". If you are copying someone else's code. Understand well purpose of the code.

Now you might ask "what the hell you are talking about?" Probably i will answer "Just angry to a mindless coder."

Look at the sample i choose for you and you will understand why i want to cry!

codingtragedy001

1 QuestionPage = QuestionPage.Replace("id=radiobutton_A", " id=radiobutton_A_" & QuestionID & " onclick=ControlTEST(this.id.split('_')[2]); ")

this is very bad written ASP.NET web application VB.NET code-behind code. Our genious programmer replacing id value with a new one and appending a javascript method call for onclick event. In that javascript call our programmer parses the control id with split and gets the id back and passes the Question id value to the javascript method. But forgets to "think" the value is already there and can be directly appended to the text.

And this is what i'm talking about:

1 QuestionPage = QuestionPage.Replace("id=radiobutton_A", " id=radiobutton_A_" & QuestionID & " onclick=ControlTEST(" & QuestionID & "); ")

I like this quote: "This machine has no brain, use your own!"

Happy coding...

Bu yazıyı ilk değerlendiren siz olun

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: | Categories: Veritabanı Posted by okutbay on 28.01.2010 10:32 | Yorumlar (0)

All of the web applications that i am responsible to maintain have lots of stored procedures. And to many of them builds a SQL string and executes at the end of the procedure. Previous programmers wrote these SPs in that way because they don’t know how to handle comma separated ID values. For these cases a small table valued split function comes to help.

CREATE FUNCTION [dbo].[Split]
(
  @delimited nvarchar(max),
  @delimiter nvarchar(100)
) RETURNS @t TABLE
(
  val nvarchar(max)
)
AS
BEGIN
  declare @xml xml
  set @xml = N'<root><r>' + replace(@delimited,@delimiter,'</r><r>') + '</r></root>'

  insert into @t(val)
  select
    r.value('.','varchar(5)') as item
  from @xml.nodes('//root/r') as records(r)

  RETURN
END

You can use this function to split array of ID with IN statement.

SELECT * FROM dbo.Split(N'a,b,c,d,e', ',')
SELECT * FROM dbo.Split('1,3,6,77,34,22', ',')
select * from Members where id in (SELECT Val as Id FROM dbo.Split('2707,2708', ','))

Happy coding…

Bu yazıyı ilk değerlendiren siz olun

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: | Categories: Web Uygulaması, News Posted by okutbay on 27.01.2010 19:31 | Yorumlar (0)

My popular framework’s version 2 release candidate released.

More about:
http://weblogs.asp.net/scottgu/archive/2010/01/10/asp-net-mvc-2.aspx
http://haacked.com/archive/2009/12/16/aspnetmvc-2-rc.aspx

Bu yazıyı ilk değerlendiren siz olun

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: | Categories: News Posted by okutbay on 27.01.2010 18:28 | Yorumlar (0)

Microsoft announces beta versions of new products.

tn-ofon

Can be download here: http://w ww.microsoft.com/2010

Bu yazıyı ilk değerlendiren siz olun

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5