Wednesday 23 October 2013

How to upload multiple file in c# | asp.net | Created directory of file name

How to upload multiple file in c# | asp.net | Created directory of file name
How to upload multiple file in asp.net with directory creation.
In this article we are going to learn how to upload multiple files in asp.net with c# code.
We can also find out if file has already uploaded then there will be directory creation with existing file name.
Lets take a examples ..
If i want to upload my resume file and there is three resume so what i need to do is , first of all i will select my resume 1

then 2 and last 3..
while uploading 3 files the resume1.doc , resume2.doc , resume3.doc will be selected at same time same names directory will

be created ..
but if you have already added or uploaded any of resume out of this then it will inform you that file already exists.

import using System.IO; namespace.

.aspx page



  <tr><td><asp:FileUpload runat="server" ID="fp1" /></td></tr>
  <tr><td><asp:FileUpload runat="server" ID="fp2" /></td></tr>
  <tr><td><asp:FileUpload runat="server" ID="fp3" /></td></tr>



now code to .cs page.


  private void Fileupload()
        {
            if (fp1.HasFile)
                {
                   
                   
                    string filename = fp1.FileName;
                  string str=  FunchekFilealreadythere(filename);
                  String filePath = Server.MapPath(@"~/upload_resume/"+str+"/"+ fp1.FileName);
                 fp1.SaveAs(filePath);//will add file name in file name directory.
            }

                if (fp2.HasFile)
                {
                 string filename1 = fp2.FileName;
                 string str1 = FunchekFilealreadythere(filename1);
                 String filePath1 = Server.MapPath(@"~/upload_resume/" + str1 + "/" + fp2.FileName);
                 fp2.SaveAs(filePath1);

                }


                if (fp3.HasFile)
                {
                    string filename2 = fp3.FileName;
                    string str2 = FunchekFilealreadythere(filename2);
                    String filePath2 = Server.MapPath(@"~/upload_resume/" + str2 + "/" + fp3.FileName);
                    fp3.SaveAs(filePath2);

                }


           
            else
            {
                Response.Write("uploaded");
            }
        }

        public string    FunchekFilealreadythereg filename)
        {
            string nm=filename ;
            string[] fnm=new string [1];
            fnm=nm .Split ('.');//will just take file name not extension.


            if (!System.IO.Directory.Exists(Server.MapPath(@"~/upload_resume/" + fnm[0] + "")))
            {
                System.IO.Directory.CreateDirectory(Server.MapPath(@"~/upload_resume/" + fnm [0]+ ""));
            }
            return fnm[0];
           
        }

here i have shown how to upload three files and create directory as well .
You can upload multiple files and create directory  how much you need.

System.Web.HttpException: 'HtmlSelect' cannot have children of type 'LiteralControl'.

System.Web.HttpException: 'HtmlSelect' cannot have children of type 'LiteralControl'.
System.Web.HttpException: 'HtmlSelect' cannot have children of type 'LiteralControl'.

if you are getting this type of error while executing on running your asp.net application

in c# or in vb.net you must know about real cause or from where this error is occurring.

lets.. reavel this now what i did i just took

<select>
<option>
some information
</option>

</select>

and added runat="server" at .aspx page .


<select size="1" name="region" id="region"  runat="server">

now if we  run its gives error System.Web.HttpException: 'HtmlSelect' cannot have children

of type 'LiteralControl'....
to remove this error and make your application work easily..just add form name in your

.aspx pahe and add then add this line of code to .cs page.

remove runat="server"
Request.Form["region"].ToString();
and try now hope its works..

Sunday 20 October 2013

Sql command set | DML(Data Manipulation language) | Insert | Update | Delete

Sql command set | DML(Data Manipulation language) | Insert | Update | Delete
What is DML?
"Sql command set".
1-> "DML(Data Manipulation language)".
DML includes select ,insert , update , delete .
Let's study all there functionality one by one.

Database names:Stud
Table Name:student

i> Select;
we use select to fetch data from table or we can say to get record from table
use stud
select * from student.
here we can apply condition also like using where clause.
select * from student  where id=234

ii>Insert :
to insert  new record  in respected table we use insert.
insert into student values ("enter records you want to insert").


iii>Update 
to done modification in existing record.
update table table_name set column_name name where clause.

iv>Delete:
to delete unwanted records from table.
delete from table_name where column_name =parameter;

sql command set | DDL(Data definition language). | create | Alter | Drop

sql command set | DDL(Data definition language). | create | Alter | Drop
"Sql command set".
1-> "DDL(Data definition language)".
DDL includes Create ,alter , drop,truncate , comment , rename.
Let's study all there functionality one by one.

i->Create
 Create used  to create new table and object.
or you can create many tables and objects.
examples.
to Create table.
Create table student
(
id int identity primary key,
name varchar(20),
roll_no int
)
ii->Alter
 Used  to modify structure of table and other object..
alter table student alter name varchar(100)
using this query we can change size of column .
alter table student add  fee int.

iii->drop
Drop is used to drop table or column of table or object.
alter table student drop column name.
drop table student.
drop database stud.
we can drop database also by using drop keyword or command.


iv->Truncate 
Truncate use to delete all data present in the table.
But not table structure means , table will be there but it won't show any of record.

Truncate table Table_name
Truncate table student.

v->Comments
to add comments in procedure.

sp_insertrecord --'1','abcval'


vi->Rename
to rename  single table or multiple table in same database.
to rename single or multiple column in same table.

sp_rename 'existtablename' ,'renamedtablename'
SP_RENAME 'student.roll_no' ,'roll'  --to rename column name

SP_RENAME 'student' ,'stud'

sql server 2005/2008 | primary key | Identity key | Auto increment

sql server 2005/2008 | primary key | Identity key | Auto increment
how to set identity by query in table .
while creating by query in sql server 2008-2005 if you want to add
primary key with identity then you need to add primary key with identity at same time.
or if  you have already added then alter that  column but need to take care of  it.
here i have shown how to add identity with primary key in sql server 2005 and sql server 2008.
db name is stud
and table name is student.

user stud
create table student
(
id int NOT NULL primary key identity ,
roll int not null,
name varchar(30) not null

)