Notes eMeroo(Some TechTips);

January 4, 2009

Shrinkster.com (shrink your long URLs)

Filed under: Misc — emeroo @ 10:29 pm

Shrinkster can solve the problem of long URLs by shrinking them to another friendly short URL has the following signature : shrinkster.com/- – - -

so this is my original URL : http://emeroo.wordpress.com/2008/12/30/add-footer-to-all-pages-of-sharepoint-site-defaultmaster-customization/

and this is the Shrinkster URL: http://shrinkster.com/13lo

so I can tell about url easily by knowing only the characters (here are 13lo ) after shrinkster.com

I think it will be usefull in diffrent cases

Hope this helps
Amira

December 30, 2008

Add footer to all pages of sharepoint site (Default.master customization)

Filed under: SharePoint — emeroo @ 10:36 am

Here’s a small task for Default.master customization; my goal is adding footer to all pages of sharepoint sites.

Requirement: Add the following footer to all pages of sharepoint –>The CompanyTM. Copyright© 2008
To Do: open the main master page which located at the following path –> C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\GLOBAL\Default.master

Move to the following area

<tr>
<td class=”ms-pagebottommarginleft”><IMG SRC=”/_layouts/images/blank.gif” width=1 height=10 alt=”"></td>
<td class=”ms-pagebottommargin”><IMG SRC=”/_layouts/images/blank.gif” width=1 height=10 alt=”"></td>
<td class=”ms-bodyareapagemargin”><IMG SRC=”/_layouts/images/blank.gif” width=1 height=10 alt=”"></td>
<td class=”ms-pagebottommarginright”><IMG SRC=”/_layouts/images/blank.gif” width=1 height=10 alt=”"></td>
</tr>

Update it to

<tr>
<td class=”ms-pagebottommarginleft”><IMG SRC=”/_layouts/images/blank.gif” width=1 height=10 alt=”"></td>
<td class=”ms-pagebottommargin”><IMG SRC=”/_layouts/images/blank.gif” width=1 height=10 alt=”"></td>
<td class=”ms-bodyareapagemargin”>
<TABLE border=”0″ width=”100%” cellspacing=”0″ cellpadding=”0″>
<TR>
<TD class=’ms-vb2′ >
<p class=”style1″  align=”center”>The Company&trade;. Copyright© 2008</p>
</TD>
</TR>
</TABLE>
</td>
<td class=”ms-pagebottommarginright”><IMG SRC=”/_layouts/images/blank.gif” width=1 height=10 alt=”"></td>
</tr>

Now you’ll get the footer added to all pages

null

Hope this helps
Amira,

December 27, 2008

Branding and customizing EditControlBlock(ECB)

Filed under: SharePoint — emeroo @ 7:45 pm

Branding sharepoint Site is one of the problems that you may face while working with MOSS 2007.
Simply you can build a feature to customize the most of sharepoint menus, by working with the ElementManifest file say “elements.xml”.
Here’s the
Default Custom Action Locations and IDs that will help in customizing menus, and this topic illustrates How to: Add Actions to the User Interface .

This topic will illustrate another branch of branding sharepoint, which is customizing context menu in Document Library. You can add item to this context menu by following the way that is illustrated in the previous links. You will use the location of “EditControlBlock”. But if you target an advanced actions for example adding sub context menu to one of the main context menues, you should follow this topic.

Problem:
I need to add sub context menu named (Document Library) to “Send To” menu, and add items to Document Library. as shown below

CustomContextMenu


Solution:
The workaround of this problem is editing at JavaScript file of MOSS located @ “Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\1033″.

Step1: You will go to this function AddSendSubMenu(m,ctx) at CORE.JS, where
- m is the menu object.
- ctx provides HTTP context information about the web request.

Step2: and after those two lines

1:      var sm=CASubM(m,strDisplayText,"","",400);
2:      sm.id="ID_Send";
@Line 1: define sm which instructs to add strDisplayText to m, where
            - strDisplayText: is now assigned to “Send To”
            - m: is representing the main Context Menu

Step3: Start writing this JavaScript code snippet 
   1: //start override
   2:
   3:         //add "Document Library" item to "Send To"
   4:         var L_DocumentLibrary_Text="Document Library";
   5:         strDisplayText =L_DocumentLibrary_Text;
   6:         var docLib=CASubM(sm,strDisplayText,"","",400);
   7:         docLib.id="id_L_DocumentLibrary_Text";
   8:
   9:         var Const_DocLibs_Array=["DocLib1","DocLib2"];
  10:
  11:         //add all document ibraries exists to "Document Library" Menu
  12:         for(var cnt=0;cnt<Const_DocLibs_Array.length;cnt++)
  13:         {
  14:         var L_Doc_Text=Const_DocLibs_Array[cnt];
  15:         strDisplayText=L_Doc_Text;
  16:         strAction= "STSNavigate('"+                ctx.HttpRoot+                "/_layouts/SendToDoc.aspx" + "')";
  17:         strImagePath=ctx.imagesPath+"existingLocations.gif";
  18:         menuOption=CAMOpt(docLib,strDisplayText,strAction,strImagePath);
  19:         menuOption.id="id_"+L_Doc_Text;
  20:         }
  21:     //end override
Inside AddSendSubMenu you can add sub items or menus to “Send To”.

@Line 6: define docLib which instructs to add strDisplayText to sm, where
             - strDisplayText: is now assigned to “Document Library”.
             - sm: is representing “Send To” menu, as descriped @ setp2.
@Line 9: define an array of the sub menu items of “Document Libray”.
@Line 15: reassign strDisplayText to new name represents text defined in array.
@Line 16: define the action of each item.
@Line 17: assign strImagePath to the image that represents each menu item.
@Line 18:  call CAMOpt to assign the action (strAction) to each item (strDisplayText) at the menu (docLib). 

Conclusion:
* Use the function CASubM(menuObject,strDisplayText,“”,“”,400) to add a menu.
* Use the function CAMOpt(menuObject,strDisplayText,strAction,strImagePath) to assign an action to item of a menu.

P.S. Here is some variables at Core.js which is defined while you are in a document Library

  • ctx.HttpRoot –> http://amira-pc/NewSite
  • ctx.ListTitle –> Shared Documents
  • ctx.listBaseType –> 1
  • ctx.listTemplate –> 101
  • ctx.listName—> {63BAFD2F-6478-45B1-B487-D454470ED346}
  • ctx.view—> {FE013DBB-809C-478D-922A-5DE78471F78E}
  • ctx.listUrlDir—> /NewSite/Shared Documents
  • ctx.HttpPath—> /NewSite/_vti_bin/owssvr.dll?CS=65001
  • ctx.displayFormUrl—> /NewSite/Shared Documents/Forms/DispForm.aspx
  • ctx.editFormUrl—> /NewSite/Shared Documents/Forms/EditForm.aspx
  • currentItemCanModify –> true
  • ctx.imagesPath—> /_layouts/images/
  • originalFormAction —> display current view page (AllItems.aspx or any custom view)

,and While the context menu of a specific item is opened,

  • currentItemAppName –> Microsoft Office Word
  • currentItemFileUrl –> /NewSite/Shared Documents/New Microsoft Office Word Document.docx
  • currentItemIcon –> icdocx.gif
  • currentItemID –> 24
  • currentItemUrl –> /NewSite/Shared Documents/New Microsoft Office Word Document.docx

Guide while branding and customizing menu
Add FireBug Blug-in to your FireFox and follow DOM values to get the rest of variables’ value of core.js at any area of sharepoint.

Hope this helps Smile

Amira

December 23, 2008

Installing an assembly into GAC from Windows server 2008

Filed under: Windows Server 2008 — emeroo @ 4:16 pm
Tip of the Day 

I was trying to install an Assembly into the Global Assembly Cache(GAC) from windows server 2008. I tried two approaches and faced those problems
1st approach---> Drag and Drop my assembly from speecific folder to" C:\WINDOWS\assembly" (GAC).
problem---> I got this error Access is denied: 'AssemblyFileName.dll'.
2nd approach ---> I tried to install dll using gacutil.exe using the following command
cd c:\Program Files\Microsoft SDKs\Windows\v6.0A\bin
gacutil /i c:/AssemblyFileName.dll
problem---> but I didn't find gacutil.exe under
C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin
nor C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin
nor C:\WINDOWS\system32\dllcache
workaround---> I uploaded gacutil from other machine that is runing on windows server 2003 and has gacutil.exe in the following path
 "C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin ";to the other one that is runing on server 2008.

Hope this helps
Amira 

December 22, 2008

My favourit Firefox Add-ons

Filed under: Misc — emeroo @ 4:24 pm

Here are some Firefox Add-ons, that I always use.

  • DownThemAll: The first and only download manager/accelerator built inside Firefox!
    DownThemAll! 1.0.4
  • Gspace: This extension allows you to use your Gmail Space (4.1 GB and growing) for file storage. It acts as an online drive, so you can upload files from your hard drive and access them from every Internet capable system.
    Gspace 0.5.97
  • Firebug: You can edit, debug, and monitor CSS, HTML, and JavaScript live in any web page…
    Firebug 1.2.1
  • FoxMarks: Keep your firefox’s bookmarks synchronized in all your computers, just install it on all computer you use and sign up on Foxmarks . All your bookmarks will be saved from computer failure.
    Foxmarks Bookmark Synchronizer 2.6.0

Installing DotNetNuke

Filed under: DotNetNuke — emeroo @ 4:20 pm

This Post From My Old Blog

You can easily Install DotNetNuke. To do, follow these steps:

Step -1-
Install IIS,Visual Web Developer, SQL Server

Step -2-
Download
DotNetNuke  Extract the downloadable file Extract the file
DotNetNuke_04.08.04_Install.zip to another folder,(I extracted it to a
folder “DotNetNuke434″ located in “C:\Inetpub”)

Step -3-
*Run
DotNetNuke_04.08.04_StarterKit.vsi , the installation wizard will
appear as shown in Figure 1-1.

Figure 1-1

*Click “Next” and the install will start.
Before the actual install starts, however, you may see a message like
the one in Figure 1-2, click “Yes”.

Figure 1-2

*Now you will see a window like
Figure 1-3, click “Finish” to continue installation.

Figure 1-3

*Finally the
installation complete successfully like Figure 1-4.

Figure 1-4

Step -4-
Go
to the directory where you extracted DotNetNuke “DotNetNuke434″, Right
click and select “properties”, move to “Security” tab, and set
permission for Users to “Full Control” as shown in Figure 2-1.

Figure 2-1

Step -5-
Continue
installation as explained here

http://www.adefwebserver.com/DotNetNukeHELP/DNN4_DevelopmentEnvironment/DNN4DevelopmentEnvironment1.htm

P.S.
You may fail in setting up DotNetNuke with some errors like those :
Error 1 –> FAILURE 400 – Access to the path ‘c:\inetpub\DotNetNuke434\Portals\_default3.00.08.txt’ is denied.
Suggested Solution 1 –> http://www.dotnetnuke.com/News/SecurityPolicy/SecurityBulletinno14/tabid/1159/Default.aspx
Suggested Solution 2 –> check step -5-

Error 2 –>Failed to update database  \APP_DATA\DATABASE.MDF” because the database is read-only.
Suggested Solution 2 –> check step -5-

Hope this helpSmile
Amira

Data Flow Diagram(DFD) for a Purchasing Website.

Filed under: Analysis and Design Diagrams — emeroo @ 4:14 pm

This Post From My Old Blog

Last topic: Designing DB for a purchasing System. 1st step: ERD
I designed the ERD of a purchasing website, I described the tables and their attributes

Now I’ll design the DFD(Data Flow Diagram) of the system. But First, let me show you how does it looks like and how you can move from page to another, so you choose the item you look for.


Home Page

@Home page:
You will see all types we have in our shop, when you move over one of the types. The categories of that type will be loaded in the same page. When you choose one of these categories, you will move to the subcategories page that list its subcategories. But if the chosen category has only one subcategory, you’ll be directed to the Items page that contains all items of the subcategory.(i.e you’ll not move to subcategories page)
EX. If you chose Computer Science category that’s dropped from Books Type, you’ll be directed to Subcategories page. But if you chose HP category that’s dropped from Laptop type, you’ll be directed to the Items page directly without passing to subdirectories page. Because HP category has only one subcategory that has all items, so there is no need for moving to subcategories.
At home page you can choose one of the best sellers, then you’ll move to the itemDetails page.
Also you can search for specific item, if there are results, they will be displayed at items page.

You can sign in, and then all price items will be displayed with the equivalent currency of your country.
You can make a new registration.


Subcategories page

@Subcategories page:
You’ll be directed to this page after choosing a category from Home page, all subcategories of the chosen categories will be placed inside here.
In the left corner, there are all of the categories that dropped from the type you chose except the category you browse its subcategories now. Here the other categories of Books type.
You can choose one of the categories in the left corner. If that category has more than one subcategory, then its subcategories will be displayed in the right side of the same page. But if that category has only one subcategory, then the items of that subcategory will be displayed in the Items page.


Items Page

@Items page:
You can select any item or its related items to browse their details; also you can add this item directly to the cart


ItemDetails page

@Itemdetails page:
you can explore the item details then add to cart or back to choose another item


Buy Page

@Buy page:
you’ll see all item you had chosen and total price. Also you can remove some of these items or back to choose extra items. Now you can buy the selected items. If you agree you will directed to another page to type your secret information such name and credit card. The page will connect to bank and check your info. If true, you’ll finish buying. If not, you will be notified.

*******************************************

Now, let’s move to the DFD.
system analyst draws DFDs to
better understand the logical movement of data throughout a business. Data flow diagrams are structured analysis and design tools that

allow the analyst to comprehend the system and subsystems visually as a set of interrelated data.

Four basic symbols are used to chart data movement on DFDs :

Square: This is used to depict an external entity (another department, a

business, a person, or a machine) that can send data to or receive data from the system.

Entities should be named with a noun.
Rectangle with rounded corners: This is used to show the occurrence of a transforming

process. Process always denotes a change in or transformation of data.

Process assigns the name of whole system or a major subsystem. Use a verb-adjectivenoun

format for detailed processes.
Rectangle: which represents a data store. The data store symbol is simply

showing a depository for data that allows addition and retrieval of data. Each data store has

a unique reference number such as D1, D2, and so on to describe its level.
But here I used the SP1,SP2,SP3, and so on. Because I used stored procedures to deal with data. I used SP instead of D in the diagram to make it easy to understand. So instead of connecting with D1, D2 to retrieve items of subcategory, I’ll use only SP3.

Here are the used stored procedures:
SP1 GetCatOfType: return all categories of selected type.
SP2 CheckIfThereSubCat: check if there are more than one subcategory. If so, it return all subcategories of selected category. If there only one subcategory, it call SP3 to return the items of that subcategory.
SP3 Get ItemsOfSubCat: return all items of selected subcategory.
SP4 Search : used for searching for specific item.(I supposed the search process use this SP)
SP5 CheckValidUser: check the existence, the validity and his desire for changing price with his currency.
SP6 InsNewUser: used for registering new user.
SP7 GetItemDetails: check the type of the item, then connect with the suitable table to return the details.
SP8 GetBestSellers: return the best seller items
SP10 DelItem: used by the admin to remove any item
SP11 Updatedata: used by the admin to update any item
SP12: AddNewDate: used by admin to add new data

The arrow: that shows movement of data from one point to another, with the head of the

arrow pointing tow ards the data’s destination. A rrow s should be described w ith a noun.

Data Flow Diagram Levels:

The context diagram is the highest level in a data flow diagram and contains only one process, representing the entire system. The process is given the number zero. All external entities are shown on the context diagram as well as major data flow to and from the system. The diagram do not show any detailed processes or data stores.

Level1 is the explosion of the context diagram. Each process is numbered with an integer.

**********************************

Child Levels: Some processes on level1 may in turn be exploded to create a more detailed child diagram. The process on Diagram1 that is exploded is called the parent process, and the diagram that result is called child diagram. The processes or the child diagram are numbered using the parent process number, a decimal point, and a unique number for each child process. For example: Process 3 explode (in level 2) to create two processes 3.1 and 3.2. Process 3.2 explode(in level 3) to create three processes 3.2.1, 3.2.2 and 3.2.3 .

Here’s the Image URL:
Context: http://farm3.static.flickr.com/2011/1577378989_8faa037a42_o.jpg

Level 1:      http://farm3.static.flickr.com/2108/1577379021_10126f013d_b.jpg

Level 2:      http://farm3.static.flickr.com/2040/1578318110_2967c04610_b.jpg

Level 3:     http://farm3.static.flickr.com/2273/1578318116_7caa88cbf6_o.jpg

Amira

Designing DB for a purchasing System. 1st step: ERD

Filed under: Analysis and Design Diagrams — emeroo @ 4:11 pm

This Post From My Old Blog

I want to build a website for a shop to support e-commerce.

How can you do so??
I suppose that my store database has different types of items (clothes, books, notebooks…etc). Each type has one or more category, each category has one or more subcategory, each subcategory has many items, and each item included in one or more subcategory (and therefore it may be included in many categories but in one type).

Notes:

Any purchasing system (of two levels in its hierarchy) can use this design.

I tended to normalizing the database for better performance while updating and adding the data.

In the ClassifiedItems table (relational table), I didn’t include CategoryID but I included SubCategoryID and therefore I can reach to CategoryID.

In Items table, I included the common fields in all different items. Also I included TypeID (the type id for that item) and ShipmentCost(how much does it cost to ship this item to somewhere for example New York). I’ll describe their use soon.

In Regions table, I included RegionShipmentValue. This field specifies a value that can be multiplied by ShipmentCost field in Items table, and the result will represent the shipment cost for that item for this region. For example, the RegionShipmentValue for Egypt is 3( i.e. triple the value specified in ShipmentCost) and by multiplying them I can have the shipment cost for Egypt for specified item.
why didn’t I specify the shipment cost for each region in the table directly , and I use a mathematical operation to get shipment cost for each region?
That is because each item have a shipment cost (shipping notebook cost you much more money than shipping a book for example. So with each item, I specify its shipment cost.
In Region table, I also included EquivalentValueForDollar field. It stores the region’s equivalent value for dollar. So for example after logging in with my username, the website can show items price directly with my currency.

For more details about some of classified items, I can add some of table to the database. For example, I can add BookDetails (TypeID, SSN, PageNumber, Publisher) and ClothesDetail (TypeID, Size, Color, MadeIn) and make a direct relationship between each new added detailed table and Items table, so that I added TypeID field to Items table to get some details about the item by connecting with the detailed table directly instead of joining 6 tables (Items, ClassifiedItems, SubCategories, Categories, Types, and any detailed table)

This an example of types added and has a relationship between Item table. Here I added bookDetails table and LaptopDetails table that have details about these types.

Amira

Tips and Tricks for C# Constructors

Filed under: C# — emeroo @ 3:56 pm

This Post From My Old Blog

Hello, Here I’ll tell you some notes about constructors and some tricks that you may face while using constructors.
* Constructors never define return value (that what distinguish constructor from method).

* If you didn’t define a constructor in your class, it will be automatically supplied with the default constructor. But if you defined a constructor with parameters, the supplied default constructor will be removed and you won’t be able to use it until you explicitly define it in your class.

* If you defined your class as internal and a constructor inside it as public, so you can’t new use it in another assembly. Although the constructor is public, but the class is internal (accessed only inside the assembly that define it).

That’s a class definition in an assembly named Constructors

using System;

namespace Constructors

{

class parent

{

public parent()

{ Console.WriteLine(“Hello”); }

}

}

Try to use parent class in another assembly. Create console application and make reference to Constructors.dll

using System;
using Constructors;

namespace usingConstructor
{
class Program
{
static void Main(string[] args)
{
parent p =
new parent();
}
}
}

You’ll receive error.

* The default access modifier for the constructor is private (like methods).

* If a constructor defined as private, you can’t instanciate it outside the class. And also you can’t define a child class inherit from parent class.Why???!!

Have a look at this code

namespace Constructors

{

public class parent

{

parent()

{ Console.WriteLine(“Hello”); }

}

public class child:parent

{

}

}

When you define child class inherit from parent class, the child class not only implicitly define default constructor but also this default constructor is implicitly call the default constructor of the parent class.

And here in child class, there isn’t constructor defined explicitly, then it will be implicitly supplied with the default constructor. This default constructor will call the default constructor of the parent class. The error will be raised at this step, because the default constructor in parent class is private, so child class can’t see it.

* Constructors can take any access modifier. Protected access modifier with constructor allow child class to inherit from parent class without any errors. But if you defined constructor as protected, you can’t access it through object variable. Such as protected access modifier with methods. As I described it before.

So if you try to write this line of code inside child class, you’ll receive an error

parent p = new parent();

* Now after defining parent class as public and its constructor as protected, try to create an object from child class inside Main in the console application that we created miniuts ago.

child c = new child();

the output is : Hello

* The first statement is executed inside the constructor is calling the default constructor of the base class(be aware that if your class didn’t explicitly inherit from a base class, your class will implicitly inherit from object class. And then every constructor will call object’s default constructor).

Try this

namespace Constructors

{

public class parent

{

protected parent()

{ Console.Write(“Hello,”); }

}

public class child:parent

{

public child(){}

public child(string yourName)

{

Console.WriteLine(yourName);

}

}

}

And inside the Main, try this

static void Main(string[] args)

{

child c = new child(“Amira”);

Console.WriteLine();

child c1 = new child();

Console.Read();

}

-First line in Main, I created an object from child with a string argument “Amira”

Here it will invoke the constructor of child class that take a string and write it. But before executing this statement inside child’s constructor, it’ll invode the parent’s default constructor(which write Hello,) so the result of that statement will be Hello, Amira

-Second line in Main, insert new line

-Third line in Main: I created another object from child class, but here it will invoke the custom default constructor with no argument. This constructor as I defined do nothing except the implicit call for parent’s default constructor. So the output will be Hello,

* If parent class has no default constructor, then when the constructors inside child class try to call the parent’s default constructor, they wont find it, you will receive error. Try to change the definion of the constructor inside parent class

public class parent

{

protected parent(string s)

{ Console.Write(“Hello,”); }

}

Here the default constructor is removed, and you’ll receive an error in that statement inside child class

public child(){} //error

* As I said before, the first statement is executed at child’s constructor is thr implicit call to paren’s default constructor. You can explicitly invoke the parent’s constructor in child’s constructors through base keyword (and the explicit call allow you to invoke any constructor defined at parent class), and that explicit call will be also the first statement executed when you instanciate the child class. If you supported child constructor with explicit call, the implicit one will be removed.

Try this

namespace Constructors

{

public class parent

{

protected parent(string str)

{ Console.Write(“Hello,” + str); }

}

public class child:parent

{

public child()

: base(“Amira”)

{ }

public child(string yourName)

: base(yourName)

{ }

}

}

Try again what we wrote in main the output will be

Hello, Amira
Hello, Amira

* Also you can make explicit call to a constructor that is defined inside the class through this keyword(that is instead of the explicitly call to parent’s constructor or instead of the implicitly call to parent’s default constructor).

So change child class definition to

public class child:parent
{
public child()
: base(“Amira”)
{ }
public child(string yourName):this()
{ Console.WriteLine(“\nBye”); }
}

Run the console application again, the output will be

Hello, Amira
Bye
Hello, Amira

* you can overload the constructor, the code you wrote before, you overloded child’s custom default constructor with an overloaded constructor with one parameter.

* Constructors can be defined as static, but you allowed to define only a single static constructor. And this static constructor doesn’t take any access modifier and also doesn’t take any parameters.

* Static constructor executes only one time, and executes before the other constructors.

Here inside StaticConstructor class, I defined static constructor which prints a message to inform the user when the static constructor is invoked and also to initialize static field (y)

public class StaticConstrucor

{

public int x;

public static int y;

static StaticConstrucor()

{

Console.WriteLine(“static constructor is invoked now”);

y = 2;

}

public StaticConstrucor()

{

Console.WriteLine(“x={0} and y={1}”,x,y);

}

public StaticConstrucor(int x)

{

this.x = x;

Console.WriteLine(“x={0} and y={1}”, x, y);

}

}

* The runtime invokes the static constructor when it creates an instance of the class or before accessing the first static member invoked by the caller. Try this snippet of code inside the Main method

StaticConstrucor s = new StaticConstrucor();
StaticConstrucor s1 = new StaticConstrucor(3);
StaticConstrucor.y = 9;
StaticConstrucor s2 = new StaticConstrucor();

Here the static constructor invoked only once when I instanciated StaticConstructor class. So the output will be

static constructor is invoked now
x=0 and y=2
x=3 and y=2
x=0 and y=9

Also it can be invoked automatically before invoking the static member y, try only this statement
Console.WriteLine(StaticConstrucor.y);

Here the output will be

static constructor is invoked now
2

That all what I remembered about constructors. I wish I covered this topic well, and I hope that helps :D

Amira

How to Copy all Photos in a tree of Directories?

Filed under: C# — emeroo @ 3:54 pm

This Post From My Old Blog
I have a Directory named photo,this directory organizes my all my photos. It contains set of subdirectories (such as Stars, Family, Work, …etc) and inside each subdirectory there are other subdirectories, for example in Family directory I have some photos in addition to 2 directories (Father’s Family and Mother’s Family) and inside each one of them there are some other directories and so on.

How to get a copy of all these photos inside the directory called photo and all photos inside the tree of its subdirectories up to the 3rd degree of photo directory’s depth ??!

   1: using System;
   2: using System.IO;
   3:
   4: namespace CopyPhotos
   5: {
   6:     class Program
   7:     {
   8:         public static int i = 0;
   9:         //create new directory in dirve D
  10:         static DirectoryInfo dir = new DirectoryInfo(@"D:\MyPhotos");
  11:
  12:         //Generate a string represents the full path for each copied photo
  13:         public static string GenerateImgName()
  14:         {
  15:             string name = "IMG" + i++.ToString();
  16:             string fullPath = @dir.FullName + @"\" + name + ".jpg";
  17:             return fullPath;
  18:         }
  19:
  20:         //copy each jpg photo in specefied directory
  21:         public static void CopyPhotosInDir(DirectoryInfo d)
  22:         {
  23:             foreach (FileInfo f in d.GetFiles("*.jpg"))
  24:                 f.CopyTo(GenerateImgName());
  25:         }
  26:
  27:         //copy each photo in the directory D:\Library\Photo and
  28:         //also copy each photo in each subdirectory up to the 3rd depth of subdirectories
  29:         public static void CopyAllPhotosInRootDir()
  30:         {
  31:             DirectoryInfo di = new DirectoryInfo(@"D:\Library\Photo");
  32:             CopyPhotosInDir(di);
  33:             foreach (DirectoryInfo d1 in di.GetDirectories())
  34:             {
  35:                 CopyPhotosInDir(d1);
  36:                 foreach (DirectoryInfo d2 in d1.GetDirectories())
  37:                 {
  38:                     CopyPhotosInDir(d2);
  39:                     foreach (DirectoryInfo d3 in d2.GetDirectories())
  40:                         CopyPhotosInDir(d3);
  41:                 }//end second foreach
  42:             }//end first foreach
  43:         }//end CopyAllPhotosInRootDir
  44:
  45:         static void Main(string[] args)
  46:         {
  47:             //create the directory D:\MyPhotos
  48:             dir.Create();
  49:
  50:             //copy all photos inside D:\Library\photo Directory
  51:             CopyAllPhotosInRootDir();
  52:         }
  53:     }
  54: }

this executable assembly copies all the jpg files to D:\MyPhotos, you can copy all photos by changing Line 23 to

foreach (FileInfo f in d.GetFiles())
Downlod the program
hope this helps, smile_regular

Amira

Next Page »

Blog at WordPress.com.