Wednesday, October 10, 2007

Blog's view changed!!! :(

Hi there,
Unfortunately I have to change the face of the blog. The reason for this action that the current view does not fit well when a code snippet is post - like in my last post. I do not like tthe current design very much but this is the only one template that fits my needs. I'll try soon to edit the template and make it with a little bit better design.

Tuesday, October 9, 2007

Using exsiting IE cookies with HttpRequest

I've come accross an idea of making my own web spider with .Net. My tests were to grab information from the Experts-exchange site. I've used a code like this

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

The request passes correct and getting the response was working well also. However the content of the response was not the correct one - I mean that it was different than the one I can see if I open an explorer.

What was the difference? The difference was the cookies! When I open the Internet Explorer and navigate to EE the EE server accepts me as logged in user using my cookies. However using the programatically created web request no cookies are associated with the request and the server does not show me the information I want.

During some research and some test I've come across the InternetGetCookie function. This function allows you to get the cookies stored by the Internet Explorer and assign them to your web request.

Here is the code I've come to:



public class RequesstWithCookie
{


[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]

static extern bool InternetGetCookie(string lpszUrlName, string lpszCookieName,
[Out] StringBuilder lpszCookieData, [MarshalAs(UnmanagedType.U4)] out int lpdwSize);


CookieContainer cookies;


public RequesstWithCookie(String siteUrl)

{

LoadCookies(siteUrl);

}


public HttpWebRequest CreateRequest(string pageUrl)

{

Uri uri = new Uri(pageUrl);


HttpWebRequest request = null;
request = (HttpWebRequest)WebRequest.Create(uri);
request.CookieContainer = cookies;


return request;

}


private void LoadCookies(String url)
{


cookies = new CookieContainer();
Uri uri = new Uri(url);


StringBuilder cookieBuilder = new StringBuilder(new string(' ', 256), 256);

int cookieSize = cookieBuilder.Length;


if (!InternetGetCookie(url, null, cookieBuilder, out datasize))

{

if (datasize <> 0)

{

return;

}


cookieBuilder = new StringBuilder(datasize);

InternetGetCookie(url, null, cookieBuilder, out datasize);

}


cookies.SetCookies(uri, cookieBuilder.ToString().Replace(";", ","));

}

}




Hope this code will help somebody else to not lose an hour or more to find this out.

Wednesday, October 3, 2007

Second edition of DevReach finished

This was just a wonderful event. I've been for second time on the DevReach in Sofia, Bulgaria and it was just amazing. For second time I have the ability to participate in sessions of Richard Campbell, Stephen Forte and Carl Franklin. I also participate in a session of Miguel Castro that is another amazing speaker.

Hope that this event will developed itself in future and will bring to Bulgaria more and more speakers of this rank.

There was a little problem with the rooms - some of the rooms was to small to hold everyone that wish to listen Stephen Forte or Miguel Castro. Hope that next year this part of the event will be better.

Thursday, September 13, 2007

DevReach event,Sofia, Bulgaria; 1-2 October, 2007

There will be a realy good event this year about developers in Sofia. This will be the second edition of the DevReach. I think that the first edition was one of the best developers events in Bulgaria and as I can see in the speakers' list and the sessions titles - this year we should expect much more ( Richard Campbell, Dino Esposito, Stephen Forte, Carl Franklin and more).

There is a discount if you register before 18th of September, so hury.

Wednesday, September 12, 2007

Experts exchange solutions

This is a list with solutions provided by the experts in the Experts exchange for the last week.Remember that if you want to see the solution you must register in the site first.

.NET
text box label backcolor change on the fly
CLR Integration: Visual Studio 2003, SQL Server 2005
How can I make the child Form's ToolStrip merge with it's parents? (.NET C++/CLI)
How can I tell if the .Net Framework has been installed on a network
Using vb.net, how to send POST request with post data and save the binary response to a file?
Difference between standard and pro version of visual studio
Dynamic Parameter List
License a dll
Unable to Run Exe from Another PC
WebDav & Exchange: Create appointment, avoid overwrite existing one

C#
License a dll
How do I capture the information of the Toolstripmenuitem that was clicked
Unable to Run Exe from Another PC
Menustrip window forms - how do I find the hierarchy of menu items that lead to the menu item clicked and close the dropdownitems
aggregattion in datagridview 2.0
WebDav & Exchange: Create appointment, avoid overwrite existing one
Error loading image

VB.NET
Using vb.net, how to send POST request with post data and save the binary response to a file?
How can I get a list of groups in Active Directory and find out who is in those groups
How to communicate with a device (printer or something else) using an ethernet card
Obtaining Host IP Address
Row Already belongs to this table
Function () with multiple Return values
'Send' is ambiguous across the inherited interfaces 'Outlook._MailItem' and 'Outlook.ItemEvents_10_Event'.
Error Handling in MS Word, Merged rows count issue
Dynamic Parameter List

ASP.NET
text box label backcolor change on the fly
How can I tell if the .Net Framework has been installed on a network
Understanding "Public Shared" Declaration

Tuesday, September 4, 2007

A trip to an ancient world

Last week my dream came true - I've been on a trip to Rome.
Just one week that allows me to see some of the greates things of the world - monumentals, churches and wonderful night life.

It was a pleasure to see another world that was the most powerfull empire in the past. Everything in Rome is fulfilled with energy, glory of the past and smile of the present.


This is a town where you can spent a life and a half to see, understand and become a part of it - not more or less. A life and a half. You can see a monumental or a church right after each corner, you can feel the power of the Catholic Church (even you are not a Catholic).

However I felt the calmness only in those small churches that you can not see on the map. The cursches on those small streets that are not named on the map.

When you see the gloriest Basilica St. Pietro, the Vatican's Museums you will understand why you must another life and half devoted to Rome.

And of course the trip will be incomplete if you don't feel the night life of rome with all the smiled faces of the Italian people, artists and musicians.

If you can afford it - you must definitely go to Rome.









Monday, August 20, 2007

Some good links August 20

.NET
Boxing/Unboxing In .NET
System Setup for .NET 3.0 and .NET 3.5
NGEN perf boost in red bits
The .NET Show on Silverlight
Callbacks, ConcurrencyMode and Windows Clients
Enterprise Library 3.1
C# static constructors are called on demand, not at startup
Analyzing .NET Patches
Materials on .NET FAQs List
10 Things You Should Know About Microsoft's Silverlight
Extension methods and .NET 2.0

LINQ
Multiple Enumeration of LINQ results
LINQ to SQL in Beta 2
LINQ to SQL (fka DLinq): What's new in Orcas beta2
Inserting new records with the ListView & LinqDataSource
LINQ to SQL (Part 6 - Retrieving Data Using Stored Procedures)

Web
Make your ASP.NET application extendable
ASP.NET Orcas Designer Customization
Master Page Reuse Across Applications
ASP.NET 2.0 FileUpload Server Control
How Do I: Determine Whether an Asynchronous Postback has Occurred?
Storing And Displaying Image From Database
Cool new ASP.NET 3.5 and Silverlight demo application
Strong password checker online
Developing IIS7 modules and handlers with the .NET framework
Make your web application run faster
GridView and Paging Alignment
Workflow + InfoPath Forms, Form is not workflow enabled??

Tools
DatePicker in ASP.NET 2.0 and AJAX Control Toolkit
Nevron .NET Vision Q2 2007 now available - AJAX Support, Gauges and many more
VS 2008 Tools menu

Other
Prepare for growing projects
Reading to Be a Better Developer - The Coding4Fun DevKit
Generic Methods
Smart enumerations
Design Patterns
Fading Forms In and Out
Silverlight Controls
Automatically GAC an assembly after a build and include debug info.
The Daily Grind 1207
Design Patterns
When BizTalk meets SharePoint, it makes sense…
ESB Guidance
What is the order of evaluation in C#?
Why the debugger will not hit your breakpoints?
E -Books Collection( Free Torrent Download)
Microsoft Interview Questions
Running FxCop and the quirks
CopySourceAsHtml in Visual Studio 2008
SOA in the Real World
Microsoft Biztalk Server 2006 Management Pack for Operations Manager 2007
Using managed code to detect what .NET Framework versions and service packs are installed
Building LINQ Queries at Runtime in F#
A couple SharePoint logging tricks (Dev Environment only)
Mixing VS2008 with VS2005

Wednesday, August 15, 2007

Experts exchange solutions

This is a list with solutions provided by the experts in the http://www.experts-exchange.com/ for the last week.Remember that if you want to see the solution you must register in the site first.

.NET

Dialing/Displaying Phone numbers on a PDA Phone
Build options in VB2005
kill keyboard mouse
is process active from process ID
Marshal array of strings
How to pass a dynamic two-dimensional array from c# to c++
Check if the program is in developing mode
physical html files on fly asp.net vs2005
Restore Application/VB.Net 2005
DataSet, BindingNavigator and DataGridView
Crystal Report Export options
VS2005 : Saving after each change

C#
kill keyboard mouse
is process active from process ID
How to pass a dynamic two-dimensional array from c# to c++
Check if the program is in developing mode
physical html files on fly asp.net vs2005

VB.NET
Encrypting / Decrypting String Data
Timed out. This may have occurred because all pooled connections were in use and max pool size was reached. cmd.Connection.Open()
Restore Application/VB.Net 2005
DataSet, BindingNavigator and DataGridView

ASP.NET
Export part of webpage to Excel
How to Implement Right Click Event
Encrypting / Decrypting String Data
server side redirection
Timed out. This may have occurred because all pooled connections were in use and max pool size was reached. cmd.Connection.Open()
OO ASP.net - trying to understand the principles of using objects with ASP.net
Error when attempting to write out XML file

Monday, August 13, 2007

Some good links August 13

.NET Framework 3.5
http://dotnetguts.blogspot.com/2007/07/net-framework-35-new-features.html

http://shailkpatel.blogspot.com/2007/06/new-stuff-in-net-framework-35.html

http://msdn.microsoft.com/msdnmag/issues/07/04/CLRInsideOut/#S6

.Net framework version comparison
Adventures in .NET 3.5 Part I, Part II, Part III, Part IV
ASP.NET 3.5 controls
LINQ Changes from Orcas Beta 1 to VS 2008 Beta 2
Speed Test: A No-Code LINQ-Based ASP.NET 3.5 Page
Introduction to Visual Basic 9.0 Features
Changes in the .NET BCL between 2.0 and 3.5
Relaxed Delegates

Web
Welcome to patterns & practices Web Client Guidance Community site
Make your web application run faster
SOAP Header Extensions How-To
The Remaining Nine "Working with Data in ASP.NET 2.0" Tutorials
Hosting ASP.NET for .NET Framework 3.5 Beta 2 in Medium or Partial Trust
ListView and GroupTemplate Example
Using XML Web Services in Traditional ASP
How To: Create an ASP.NET AJAX Toolkit Extender Control to Extend a GridView
The asp:ListView control (Part 1 - Building a Product Listing Page with Clean CSS UI)
IIS/ASP.NET Settings and Virtual Directory Inheritance
LINQ
Querying XML documents with LINQ to XML
LINQ to SQL : Using Transaction
Using LINQ to XML (and how to build a custom RSS Feed Reader with it)
LINQ, Lambda, and Generics
LINQ samples
Tools
NxBRE -The open-source rule engine for the .NET
Diagrams with Reflector and the Graph Plugin (Part 1)
Capture Entire Web Page
JetBrains releases ReSharper 3.0
FlexWiki 2.0 Beta 2 Released
Dynamic Application Configuration Solution
West Wind Html Help Builder Update
Export from Database In Different Formats: PDF, Excel, Access, XML, HTML, FoxPro, CSV
The Code Project Browser Add-in for VS 2005
Microsoft Visual Studio 2008 SDK August 2007 Community Technology Preview
Other
Oracle bulks up .NET tools
Fixing a VS.NET 2008 Beta 2 ASP.NET Debugging Issue on Vista: "Strong name validation failed"
Dynamically invoke a method, given strings with method name and class name
Using the platform for XML (and how to create a custom RSS Feed Reader c)
Unit Testing Multithreaded methods
Introduction to Development Tools for Windows Mobile-based Devices
How to Debug MPI Applications in Visual Studio 2005 (Part 1)
How to Debug MPI Applications in Visual Studio 2005 (Part 2)
Great New ASP.NET 2.0 Data Tutorials Published
Localizing .NET Enums
An Intelligent Data Layer
ASP.NET GridView Image Command Button Problem (multiple PostBacks)
XmlWriter and Schema
Visual Studio 2008 Shell
Final TFS 2008 Feature List
Concurrency in .NET
.NET Rocks! - Introducing Acropolis
Interview
IIS and .NET 2.0 interview questions
Interview questions for .NET

Monday, August 6, 2007

Some good links August 06

Building LINQ Queries at Runtime
User bar code fonts in C#.net

ASP.NET 2.0 Membership, Roles, Forms Authentication, and Security Resources

Partial Methods

Install a Windows Service in a smart way instead of using the Windows Installer MSI package

How long before ALT.NET becomes NOT.NET?

Improving Performance of Asp.Net Application

Using Reflection to Test Web Controls - Part I and Part II

Authentication and Session

Adding Custom Dialog to Visual studio .Net 2003 project

A brief architecture overview of VMware ESX, XEN and MS Viridian

A Developers Toolkit for C# and .Net

Agile Tools for .NET

Automated testing of ASP.NET web applications using Selenium

ASP.NET 2.0 Features - Ten things you might not know about ASP.NET 2.0

C# Language Specification

Cascade XSL

All Roads Lead to Rome (How you can maintain scroll position on postback)

Multi-threading in .NET: Introduction and suggestions

Basic Workflow Execution

Implementing a generic CSV file importer using reflection and attribute based programming in C#.NET

Sending mails:

http://www.codeproject.com/aspnet/EasySMTP_package.asp http://www.codeproject.com/aspnet/smtpmail.asp http://www.codeproject.com/aspnet/techblaster.asp http://www.codeproject.com/useritems/Send_Emails_in_ASPNET20.asp http://www.codeproject.com/useritems/SendMailSMTPWebConfig.asp http://www.codeproject.com/useritems/Seding_Mail.asp http://aspnet.4guysfromrolla.com/articles/072606-1.aspx http://aspnet.4guysfromrolla.com/articles/080206-1.aspx

Life with Visual Studio 2008

SOAP messages exchange between .Net clients and Axis Apache web services

Generic sorting argorithm (QuickSort)

How To: Access Underlying Data of the ObjectDataSource

The EventPool revisited

.NET FRAMEWORK 3.0 is worth learning? by Niraj Yadav

Inside the Grid: Part 1

Generic TCP/IP Client/Server

Reading XML document fragments in .NET

Medium Trust and Visual Studio codename 'Orcas' Beta 2

How to extend the native MessageBox dialog in .NET

Monday, July 30, 2007

Experts exchange solutions

These are the best solutions provided by the experts in the www.experts-exchange.com for the last week.

Remember that if you want to see the solution you must register in the site first.

.NET
ASP.NET
VB.NET
C#
.NET Compact

Some good links July 30

Moving Projects/Solutions between Orcas and Visual Studio 2005 - http://www.west-wind.com/weblog/posts/122975.aspx

Nothin but .NET - Tips and Tricks - Day 3 - http://weblogs.asp.net/bsimser/archive/2007/07/26/nothin-but-net-tips-and-tricks-day-3.aspx

How to Use Web.Config in ASP.NET and ASP - http://vgbsoft.blogspot.com/2007/07/how-to-use-webconfig-in-aspnet-and-asp.html

A Generic State Machine and Attempt to Generic Component - http://www.codeproject.com/useritems/GenericStateMachine.asp

AWUI - a simple web user interface library with AJAX support - http://www.codeproject.com/Ajax/awui.asp

Using AJAX to populate a drop-down list in ASP.NET - http://www.codeproject.com/Ajax/PopulatingDropDownLists.asp

Email templates - http://www.codeproject.com/useritems/mailtemplates.asp

Sorting collection of custom types generically - http://www.codeproject.com/useritems/sorting_custom_types.asp

Nice VS 2008 Code Editing Improvements - http://weblogs.asp.net/scottgu/archive/2007/07/28/nice-vs-2008-code-editing-improvements.aspx

Dynamic Message Display (ASP.NET) - http://www.codeproject.com/useritems/Dynamic_Message_Display.asp

Diffrence between Oracle and sql server 2000 - http://www.dotnetspider.com/kb/Article3289.aspx

Monday, July 23, 2007

Interview questions

Long time ago Scott Hanselman post a blog's articles about ASP.NET Interview Questions and more generic questions about .net.
Today I have read another blog's post of Rodney Vinyard that gives more questions about interview about .Net framework - check it out.

New : Giving and taking an Interview (A brief article on interviewing both as an interviewer and interviewee)
New : IIS and .NET 2.0 interview questions Interview questions for .NET (Update 13/08/2007)

Wednesday, July 18, 2007

.NET Tips & Tricks by Michael Nemtsev

Today I've been reading about new features in .NET Framework, how the things can become better from a developer point of view and discovered an article written by Michael Nemtsev, Microsoft MVP that is collect a really huge list of facts and tips about .NET Framework - general issues, thrading, web applications, etc. Also this list become much more valued with the attached links with more information about each tip.

You must read and try to learn it as much as you can.

Monday, July 16, 2007

Count .NET projects lines

When developing an application using either C#, Visual Basic or C++ in .NET projects we discard to think about what is the amount of the code that we produce, what of the code is commented, etc.
However it is very usefull to have information how many lines of code are written in a file or in a project. Also how many lines of comments are included and so on.
This kind of information will not change anything in your project but should you direct you if the things are going well and can quickly answer you some simple questions - Is there any comments in this file/project? What is the total amount of code lines produced from the beginning of the project? What is the correlation between the autogenerated code and your 'true' code.

I've found a very nice utility that counts the number of lines in a C#, VB or C++ .NET solutions or projects related with the above questions.

Check this out.

How I am becoming a better developer, part 1 of infinity

Today I've read some very useful blog post that show me a Justice Gray's post about what and how a professional can be more than professional. Read this post! It's worth!! Also there are links to very cool and usefull books.

Friday, July 13, 2007

Create an ASP.NET ProgressBar

I was facing a lot of questions like "How to see the progress of uploading large files on my web site?" or "Can I integrate an upload progress in my web pages?" and etc. I have found a very good article for creating such progress bar on CodeProject but today reading the help.net blog finds out that it can be much easier to do that stuff. Check this article and make your life happier.

New (24/7/07): Here is another progress bar using ajax: AJAX file upload

Thursday, June 14, 2007

Do you know what has .NET Framework in it?

I just have found such a perfect post:
The Most Useful .NET Utility Classes Developers Tend To Reinvent Rather Than Reuse written by Phil Haack. This is a wonderful discussion with samples what is included in the .NET Framework that we should use direct from the System namespaces instead of writting custom methods.
I sugest you to read the comments too. There are some very useful notes.

Wednesday, May 9, 2007

Friday, January 12, 2007

Reflection: Modify value types by reflection

Yestarday I have seen a post in Experts-Exchange related with using reflection on structure in .net. The guy is trying to modify the content of the structure via reflection by passing an instance of the structure to a method. On first sight this is something real normal - using reflection go through fields, properties, etc., change values, invoke members and at the end of the method you will have complete new data in your structure.

Yes, but no thanks. This could not happend because the structure is value type and not reference type. In this case the code

MyStruct _name = new MyStruct();
_name.familyName = "Smith";
_name.givenName = "John";
foreach (FieldInfo fi in _name.GetType().GetFields())
{
fi.SetValue(_name, "set value test");
}

will not change the content of the structure at all. But this work perfect if you would use class instead of structure. I've decided to check if anybody on the net is trying to do things lilke this and of cource I saw a lot of articles on the net where programmers are talking about using ValueType object to work with strucutre in this situation.

So trying to move forward I have written this:

MyStruct _name = new MyStruct();
_name.familyName = "Smith";
_name.givenName = "John";

ValueType vt = _name;
FieldInfo[] fis = _name.GetType().GetFields();
for (int i = 0; i <>
{
FieldInfo fi = fis[i];
if (_name.GetType().IsValueType)
{
fi.SetValue(vt, "set value test");
fi.SetValue(_name, "Test");
}
}

This code should work like a sharp. In the above code when is using

fi.SetValue(_name, "Test");

the content of the structure will not be changed. But - the vt variable which is ValueType will be changed via the line

fi.SetValue(vt, "set value test");

So I believe this was the right way and the task is finished. I wanted to help the guy to change the values of the structure, I have found that using ValueType class is the right direction to do this and at the end of the code above I have the changed structure's fields.

Opps! I do not have the structure's fields changed! I do have changed the fields of the ValueType variable changed. So because the ValueType class is the base class of all value types, it is normal that you can not cast the variable vt back to the structure MyStructure type.

So at the end of writting this code I had changed the values of the fields but the result that had to return was not of type MyStruct and of type ValueType. What a hell? It is obviously that you could not change the structure's fields by reflection - BECAUSE IT IS A VALUE TYPE!

Ok! But there should be a way! There must be a way of passing to a method strucutre instance and return as a result instance of the same strucutre with changed by Reflection values.

All I had moving around is in some way calling the constructor of the structure by passing parammeters. Using Reflection is it not possible. Why? BECAUSE IT IS A VALUE TYPE!. And the code of using ConstructorInfo.Invoke will produce the same result like the code above - No change to the structure instance. Is there any other way a constructor can be called?

Yes! There is a way! In System namespace there is a class called Activator. And was happy to read the brief description of this class:
"Contains methods to create types of objects locally or remotely, or obtain references to existing remote objects. This class cannot be inherited."

So researching the class' methods I have found that there is a method CreateInstance that return the newly created instance (see that when using reflection and call the ConstructorInfo.Invoke you do not return any instance.The reflection is used the passed object and is trying to create the new instance on the passed variable).

So after reading a while and trying it I have finally written this which works like a charm:


public static MyStruct ChangeValues(MyStruct previousVersion)
{
MyStruct changedVersion = default(MyStruct);
ValueType valueType = previousVersion;

MemberInfo[] members = valueType.GetType().GetMembers();

for (int memberIndex = 0; memberIndex < style="color:#3333ff;">if (members[memberIndex].MemberType == MemberTypes.Field)
{
if (valueType.GetType().GetField(members[memberIndex].Name).FieldType == typeof(String))
{
changedVersion = (MyStruct)Activator.CreateInstance(changedVersion.GetType(), new object[] { "test", 3 });
}
}
}
return changedVersion;
}


public struct MyStruct
{
public String variableString;
public Int32 variableInt32;
public Boolean variableBoolean;

public MyStruct(String var1, Int32 var2)
{
variableString = var1;
variableInt32 = var2;
variableBoolean = false;
}
}

This finally, I think, finish the task of passing parameter of structure to the method and return a changed instance of the same structure using Reflection.

Regards

Tuesday, January 9, 2007

Debugging problems in .NET

I have faced very often these days problems when I started my Studio in Debuging mode.
Also many time in ExpertsExchange I'm talking with members in exaclty the same problems.

One of the very good document I have founded on the net is "my best friend" in all these situations. And when yestarday I found that is really hard to find this document out i decided to add another link to this document.

It is really cool to read it. Here it is