Monday, June 22, 2009

Uploading and Storing Images to Database in ASP.NET

STEP1: Creating the Database.



The following are the basic steps on how to create a simple database in the Sql Server:



1. Launch Sql Server Management Studion Express and then connect
2. Expand the Databases folder from the Sql Server object explorer
3. Right click on the Databases folder and select “New Database”
4. From the pop up window, input the database name you like and click add
5. Expand the Database folder that you have just added
6. Right click on the Tables folder and select “New Table”
7. Then add the following fields below:





Note: in this demo, I set the Id to auto increment so that the id will be automatically generated for every new added row. To do this select the Column name “Id” and in the column properties set the “Identity Specification” to yes.



Then after adding all the necessary fields, name your Table the way you like. Note that in this demo I name it “TblImages”
STEP2: Setting up the WebForm (UI)



For the simplicity of this demo, I set up the UI like this below:






STEP3: Setting up the Connection String



In your webconfig file set up the connection string there as shown below:






providerName="System.Data.SqlClient" />





Note: MyConsString is the name of the Connection String that we can use as a reference in our codes for setting the connection string later.



STEP4: Writing the codes for Saving the binary image to Database.



Here are the code blocks below:



private void StartUpLoad()

{

//get the image file that was posted (binary format)

byte[] theImage = new byte[FileUpload1.PostedFile.ContentLength];

HttpPostedFile Image = FileUpload1.PostedFile;

Image.InputStream.Read(theImage, 0, (int)FileUpload1.PostedFile.ContentLength);

int length = theImage.Length; //get the length of the image

string fileName = FileUpload1.FileName.ToString(); //get the file name of the posted image

string type = FileUpload1.PostedFile.ContentType; //get the type of the posted image

int size = FileUpload1.PostedFile.ContentLength; //get the size in bytes that

if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "")

{

//Call the method to execute Insertion of data to the Database

ExecuteInsert(theImage, type, size, fileName, length);

Response.Write("Save Successfully!");

}

}

public string GetConnectionString()

{

//sets the connection string from your web config file "ConnString" is the name of your Connection String

return System.Configuration.ConfigurationManager.ConnectionStrings["MyConsString"].ConnectionString;

}



private void ExecuteInsert(byte[] Image, string Type, Int64 Size, string Name, int length)

{

SqlConnection conn = new SqlConnection(GetConnectionString());



string sql = "INSERT INTO TblImages (Image, ImageType, ImageSize, ImageName) VALUES "

+ " (@img,@type,@imgsize,@imgname)";

try

{

conn.Open();

SqlCommand cmd = new SqlCommand(sql, conn);

SqlParameter[] param = new SqlParameter[4];



//param[0] = new SqlParameter("@id", SqlDbType.Int, 20);

param[0] = new SqlParameter("@img", SqlDbType.Image, length);

param[1] = new SqlParameter("@type", SqlDbType.NVarChar, 50);

param[2] = new SqlParameter("@imgsize", SqlDbType.BigInt, 9999);

param[3] = new SqlParameter("@imgname", SqlDbType.NVarChar, 50);



param[0].Value = Image;

param[1].Value = Type;

param[2].Value = Size;

param[3].Value = Name;



for (int i = 0; i < param.Length; i++)

{

cmd.Parameters.Add(param[i]);

}



cmd.CommandType = CommandType.Text;

cmd.ExecuteNonQuery();

}

catch (System.Data.SqlClient.SqlException ex)

{

string msg = "Insert Error:";

msg += ex.Message;

throw new Exception(msg);



}

finally

{

conn.Close();

}

}

protected void Page_Load(object sender, EventArgs e)

{



}

protected void Button1_Click(object sender, EventArgs e)

{

StartUpLoad();

}



StartUpload() is method that gets all the necessary information from the uploaded file such as the image length, size, type, filename and the image itself in a binary format.



GetConnectionString() is a method that returns the connection string that was set up from the web.config file.



ExecuteInsert() is a method that will executes the insertion of data to the database. This method takes all the necessary data to be inserted in the database.



As you can see the code above is pretty straight forward and self explanatory…

Check out my next example about "Displaying Image to Image Control based on User Selection in ASP.NET"

That’s it! Hope you will find this example useful!

Saturday, June 20, 2009

Converting Excel file into Xml

You can Easily convert Excel Sheet into Xml File by One Click
I am Writing That code Here.

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim Str As String = Nothing
Dim src, src2 As String
src = txtExcel.Text// name of .xls File
src2 = txtTablename.Text//name Excel Sheet it take multiple sheet name with seprated by comma




Str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & src & ";Extended Properties=Excel 8.0;"//connecting to Excel
Dim stringItems() As String = src2.Split(",")

Dim count As Integer
For count = 0 To stringItems.Length - 1

Dim dx As New DataSet()

Dim DA As New OleDb.OleDbDataAdapter()
Dim DS As New DataSet()

Dim str2 As String
str2 = "$"
Dim objConn As New OleDb.OleDbConnection(Str)
Dim scomman As String = "select * from [" + stringItems(count) + "$]"
Dim ada As New OleDbDataAdapter(scomman, objConn)

ada.Fill(dx, "transport")

Dim doc As New XmlDataDocument(dx)
doc.Save("C:\" + stringItems(count) + ".xml")

Next

MsgBox("Xml Files Created", MsgBoxStyle.Information, "Xml Converter")


End Sub

Tuesday, June 16, 2009

Javascript Validation

function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
{
alert(alerttxt);return false;
}
else
{
return true;
}
}
}

Friday, June 12, 2009

Network engineer interview questions

Network engineer interview questions
OSPF

* Describe OSPF in your own words.
* OSPF areas, the purpose of having each of them
* Types of OSPF LSA, the purpose of each LSA type
* What exact LSA type you can see in different areas
* How OSPF establishes neighboor relation, what the stages are
* If OSPF router is stucked in each stage what the problem is and how to troubleshoot it
* OSPF hierarchy in the single or multi areas. Cool OSPF behavior in broadcast and nonbroadcast
* Draw the diagram of typical OSPF network and explain generally how it works, DR, BDR, election, ASBR, ABR, route redistribution and summarization

STP

* How it works and the purpose
* Diff types (SSTP, MSTP, RSTP) Cisco - PVST/PVST+
* root election
* Diff. port stages and timing for convergence
* Draw the typical diagram and explain how diff types of STP work
* What ports are blocking or forwarding
* How it works if there are topology changes

ACLs

* What are they
* Diff types
* Write an example if you want to allow and to deny…
* Well-known port numbers (DNS - 53 and etc…)

QOS

* What is that
* What is the diff b/w L2 and L3 QoS
* How it works

Network:

* Draw the typical network diagram you have to deal with
* explain how it works
* What part of it you are responsible
* firewall, what is that, how it works, how it is diff from ACLs
* What problems with the network you had had and how you solved it.
* What are the ways to troubleshoot the network, techniques, commands
* network security, ways to achieve it

Switching:

* VLANs
* STP
* How a L2 switch works with broadcast, unicast, multicast, known/unknown traffic
* VRRP, GLBP
* port monitoring and mirroring
* L3 switch, how it works
* PIM sparse and dense modes


^Back to Top
Windows admin interview questions

1. Describe how the DHCP lease is obtained. It’s a four-step process consisting of (a) IP request, (b) IP offer, © IP selection and (d) acknowledgement.
2. I can’t seem to access the Internet, don’t have any access to the corporate network and on ipconfig my address is 169.254.*.*. What happened? The 169.254.*.* netmask is assigned to Windows machines running 98/2000/XP if the DHCP server is not available. The name for the technology is APIPA (Automatic Private Internet Protocol Addressing).
3. We’ve installed a new Windows-based DHCP server, however, the users do not seem to be getting DHCP leases off of it. The server must be authorized first with the Active Directory.
4. How can you force the client to give up the dhcp lease if you have access to the client PC? ipconfig /release
5. What authentication options do Windows 2000 Servers have for remote clients? PAP, SPAP, CHAP, MS-CHAP and EAP.
6. What are the networking protocol options for the Windows clients if for some reason you do not want to use TCP/IP? NWLink (Novell), NetBEUI, AppleTalk (Apple).
7. What is data link layer in the OSI reference model responsible for? Data link layer is located above the physical layer, but below the network layer. Taking raw data bits and packaging them into frames. The network layer will be responsible for addressing the frames, while the physical layer is reponsible for retrieving and sending raw data bits.
8. What is binding order? The order by which the network protocols are used for client-server communications. The most frequently used protocols should be at the top.
9. How do cryptography-based keys ensure the validity of data transferred across the network? Each IP packet is assigned a checksum, so if the checksums do not match on both receiving and transmitting ends, the data was modified or corrupted.
10. Should we deploy IPSEC-based security or certificate-based security? They are really two different technologies. IPSec secures the TCP/IP communication and protects the integrity of the packets. Certificate-based security ensures the validity of authenticated clients and servers.
11. What is LMHOSTS file? It’s a file stored on a host machine that is used to resolve NetBIOS to specific IP addresses.
12. What’s the difference between forward lookup and reverse lookup in DNS? Forward lookup is name-to-address, the reverse lookup is address-to-name.
13. How can you recover a file encrypted using EFS? Use the domain recovery agent.


^Back to Top

Read more at TechInterviews.com
Network engineer/architect interview questions

1. Explain how traceroute, ping, and tcpdump work and what they are used for?
2. Describe a case where you have used these tools to troubleshoot.
3. What is the last major networking problem you troubleshot and solved on your own in the last year?
4. What LAN analyzer tools are you familiar with and describe how you use them to troubleshoot and on what media and network types.
5. Explain the contents of a routing table (default route, next hop, etc.)
6. What routing protocols have you configured?
7. Describe the commands to set up a route.
8. What routing problems have you troubleshot?
9. How do you display a routing table on a Cisco? On a host?
10. How do you use a routing table and for what?
11. What is a route flap?
12. What is a metric?
13. When do you use BGP, IGRP, OSPF, Static Routes?
14. What do you see as current networking security issues (e.g. NFS mounting, spoofing, one time passwords, etc.)?
15. Describe a routing filter and what it does.
16. Describe an access list and what it does.
17. What is a network management system?
18. Describe how SNMP works.
19. Describe the working environment you are currently in, e.g. frequent interruptions, frequent priority shifting, team or individual.
20. What do you use to write documentation? Editor? Mail reader?
21. What platform (s) do you currently work on at your desk?
22. How do you manage multiple concurrent high level projects?
23. Describe a recent short term stressful situation and how you managed it.
24. How do you manage a long term demanding stressful work environment?
25. Have you worked in an assignment based environment, e.g. work request/trouble ticket system, and if so, describe that environment.
26. Describe what network statistics or measurement tools you are familiar with and how you have used them.
27. Describe what a VPN is and how it works.
28. Describe how VoIP works.
29. Describe methods of QoS.
30. How does ToS bit work?


^Back to Top
CCNA/Cisco admin interview questions

1. You need to retrieve a file from the file server for your word processing application, which layer of the OSI model is responsible for this function?
1. Presentation layer
2. Application layer
3. Session layer
4. Transport layer
5. Datalink layer
2. You are working in a word processing program, which is run from the file server. Your data comes back to you in an unintelligible manner. Which layer of the OSI model would you investigate?
1. Application layer
2. Presentation layer
3. Session layer
4. Network layer
5. Datalink layer
3. The IEEE subdivided the datalink layer to provide for environments that need connectionless or connection-oriented services. What are the two layers called?
1. Physical
2. MAC
3. LLC
4. Session
5. IP
4. You are working with graphic translations. Which layer of the OSI model is responsible for code formatting and conversion and graphic standards.
1. Network layer
2. Session layer
3. Transport layer
4. Presentation layer
5. Which is the best definition of encapsulation?
1. Each layer of the OSI model uses encryption to put the PDU from the upper layer into its data field. It adds header and trailer information that is available to its counterpart on the system that will receive it.
2. Data always needs to be tunneled to its destination so encapsulation must be used.
3. Each layer of the OSI model uses compression to put the PDU from the upper layer into its data field. It adds header and trailer information that is available to its counterpart on the system that will receive it.
4. Each layer of the OSI model uses encapsulation to put the PDU from the upper layer into its data field. It adds header and trailer information that is available to its counterpart on the system that will receive it.
6. Routers can be configured using several sources. Select which of the following sources can be used.
1. Console Port
2. Virtual Terminals
3. TFTP Server
4. Floppy disk
5. Removable media
7. Which memory component on a Cisco router contains the dynamic system configuration?
1. ROM
2. NVRAM
3. Flash
4. RAM/DRAM
8. Which combination of keys will allow you to view the previous commands that you typed at the router?
1. ESC-P
2. Ctrl-P
3. Shift-P
4. Alt-P
9. Which commands will display the active configuration parameters?
1. show running-config
2. write term
3. show version
4. display term
10. You are configuring a router, which prompt tells you that you are in the privileged EXEC mode?
1. @
2. >
3. !
4. :
5. #
11. What does the command “IP name-server 255.255.255.255″ accomplish?
1. It disables domain name lookup.
2. It sets the domain name lookup to be a local broadcast.
3. This is an illegal command.
4. The command is now defunct and has been replaced by “IP server-name ip any”
12. The following selections show the command prompt and the configuration of the IP network mask. Which two are correct?
1. Router(config-if)#netmask-format { bitcount | decimal | hexadecimal }
2. Router#term IP netmask-format { bitcount | decimal | hexadecimal }
3. Router(config-if)#IP netmask-format { bitcount | decimal | hexadecimal }
4. Router#ip netmask-format { bitcount | decimal | hexadecimal }
13. Which layer is responsible for flow control with sliding windows and reliability with sequence numbers and acknowledgments?
1. Transport
2. Application
3. Internet
4. Network Interface
14. Which processes does TCP, but not UDP, use?
1. Windowing
2. Acknowledgements
3. Source Port
4. Destination Port
15. Select which protocols use distance vector routing?
1. OSPF
2. RIP
3. IGRP
4. PPP


^Back to Top

Read more at TechInterviews.com
Networking and Unix interview questions

What is UTP?

UTP — Unshielded twisted pair 10BASE-T is the preferred Ethernet medium of the 90s. It is based on a star topology and provides a number of advantages over coaxial media:

It uses inexpensive, readily available copper phone wire. UTP wire is much easier to install and debug than coax. UTP uses RG-45 connectors, which are cheap and reliable.

What is a router? What is a gateway?

Routers are machines that direct a packet through the maze of networks that stand between its source and destination. Normally a router is used for internal networks while a gateway acts a door for the packet to reach the ‘outside’ of the internal network

What is Semaphore? What is deadlock?

Semaphore is a synchronization tool to solve critical-section problem, can be used to control access to the critical section for a process or thread. The main disadvantage (same of mutual-exclusion) is require busy waiting. It will create problems in a multiprogramming system, where a single CPU is shared among many processes.

Busy waiting wastes CPU cycles.

Deadlock is a situation when two or more processes are waiting indefinitely for an event that can be caused by only one of the waiting processes. The implementation of a semaphore with a waiting queue may result in this situation.

What is Virtual Memory?

Virtual memory is a technique that allows the execution of processes that may not be completely in memory. A separation of user logical memory from physical memory allows an extremely large virtual memory to be provided for programmers when only a smaller physical memory is available. It is commonly implemented by demand paging. A demand paging system is similar to a paging system with swapping. Processes reside on secondary memory (which is usually a disk). When we want to execute a process, we swap it into memory.

Explain the layered aspect of a UNIX system. What are the layers? What does it mean to say they are layers?

A UNIX system has essentially three main layers:

. The hardware

. The operating system kernel

. The user-level programs

The kernel hides the system’s hardware underneath an abstract, high-level programming interface. It is responsible for implementing many of the facilities that users and user-level programs take for granted.

The kernel assembles all of the following UNIX concepts from lower-level hardware features:

. Processes (time-sharing, protected address space)

. Signals and semaphores

. Virtual Memory (swapping, paging, and mapping)

. The filesystem (files, directories, namespace)

. Pipes and network connections (inter-process communication)