Step one: Create database and table your need.
Step 2: Create project in vs2012.
Stride 3: Create Entity Data Model. For more information read my previous blog.
Step 4: Create controller and view. Write code post-obit lawmaking in vie.
- <link href= "~/Content/bootstrap-fileupload.css" rel= "stylesheet" />
- <link href="~/Content/Photobooth.css" rel= "stylesheet" />
- <script src="~/Scripts/bootstrap-fileupload.js" ></script>
- <script src="~/Scripts/photowebcam.js" ></script>
- <style type="text/css" >
- #example
- {
- acme:300px;
- }
- </style>
- <divcourse = "pageheader" >
- <divclass = "media" >
- <divform = "pageicon pull-left" >
- <iclass = "glyphicon glyphicon-cog" ></i>
- </div>
- <divclass = "media-trunk" >
- <ulclass = "breadcrumb" >
- <li><a href="" ><i class = "glyphicon glyphicon-dwelling house" ></i></a></li>
- <li>Employee</li>
- </ul>
- <h4 id="lblSellertitle" >Add Employee</h4>
- </div>
- </div><!-- media -->
- </div>
- <divclass = "contentpanel" >
- <grade method="postal service" enctype= "multipart/course-data" id= "AddEmployeeForm" >
-
- <divclass = "col-doctor-12 form_align" >
- <divclass = "form-grouping last" >
- <characterizationform = "command-characterization col-md-4" id= "lblAvtar" manner= "text-marshal: get-go" >Profile Picture</label>
- <divform = "col-doc-8" >
- <divclass = "fileupload fileupload-new" data-provides= "fileupload" >
- <divclass = "fileupload-new thumbnail" style= "width: 200px; acme: 150px;" >
-
- <img src="http://www.placehold.it/200x150/EFEFEF/AAAAAA&text=no+epitome" alt= "" id= "imgcamera" >
- </div>
- <divclass = "fileupload-preview fileupload-exists thumbnail" mode= "max-width: 200px; max-elevation: 150px; line-pinnacle: 20px;" ></div>
- <div>
- <spanclass = "btn btn-white btn-file" >
- <spanclass = "fileupload-new" ><i class = "fa fa-paper-prune" ></i>Select image</bridge>
- <spancourse = "fileupload-exists" ><i course = "fa fa-undo" ></i>Alter</span>
- <input type="file" name= "file" grade = "default" id= "txtAvtar" />
- </span>
- <a href="#" class = "btn btn-danger fileupload-exists" data-dismiss= "fileupload" ><i class = "fa fa-trash" ></i>Remove</a>
- </div>
- </div>
- <button type="button" course = "btn btn-primary btn-sm" id= "btnbtncameraupload" style= "width:150px;" >Upload from camera</button>
- </div>
- </div>
- </div>
-
- </div>
-
- <script>
- $("#btnbtncameraupload" ).click(function () {
- if ($( "#example" ).css( 'brandish' ) == 'none' ) {
- $("#example" ).show();
-
- $('#example' ).photobooth().on( "image" , function ( upshot , dataUrl) {
-
- $("#imgcamera" ).attr( 'src' , dataUrl);
- $("#pp" ).val(dataUrl);
- });
- $('#example' ).data( "photobooth" ).resize(400, 300);
- }
-
- });
- </script>
S tep 5: Delight insert the following js file in project. For js you tin go to. http://wolframhempel.github.io/photobooth-js and download. Js file.And for bootstrap-fileupload.js you tin can become this link.
- <script src= "~/Scripts/bootstrap-fileupload.js" ></script>
- <script src="~/Scripts/photowebcam.js" ></script>
Step 6: Write the following code in controller. For the post method.
- [AcceptVerbs(HttpVerbs.Mail)]
- public ActionResult AddEmployee(usr_User UserNewAdd, HttpPostedFileBase file, FormCollection fc)
- {
- Random objrandom =new Random();
- cord Password = Convert.ToString(objrandom.Next());
-
-
-
- if (UserNewAdd.ProfilePicture != cypher && file == null )
- {
- UserNewAdd.ProfilePicture = UserNewAdd.ProfilePicture.Supercede("data:paradigm/png;base64," , "" );
- string base64 = UserNewAdd.ProfilePicture.Substring(UserNewAdd.ProfilePicture.IndexOf( ',' ) + 1);
- base64 = base64.Trim('\0' );
- byte [] chartData = Catechumen.FromBase64String(base64);
- CreateImage(chartData, UserNewAdd.EmailID.ToString() +".png" );
- UserNewAdd.ProfilePicture = UserNewAdd.EmailID.ToString() +".png" ;
- }
-
- if (file != nothing )
- {
- var ProfPicName = Path.GetFileName(file.FileName);
- var path = Path.Combine(Server.MapPath("~/ProfilePicture/" ), ProfPicName);
- file.SaveAs(path);
- UserNewAdd.ProfilePicture = file.FileName;
- }
-
-
- if (fc[ "languge" ] != null )
- {
- String languageKnownList = fc["languge" ].ToString();
- UserNewAdd.LanguageKnown = languageKnownList;
- }
-
- UserNewAdd.UserID = Guid.NewGuid();
- UserNewAdd.Password = Password;
- DateTime UserDOB =new DateTime();
- DateTime UserJoinDate =new DateTime();
- DateTime UserReleaveDate =new DateTime();
- if (fc[ "DOB" ] != null )
- {
- UserDOB = DateTime.ParseExact(fc["DOB" ], "MM/dd/yyyy" , CultureInfo.InvariantCulture);
- }
-
- if (fc[ "JoiningDate" ] != cipher )
- {
- UserJoinDate = DateTime.ParseExact(fc["JoiningDate" ], "MM/dd/yyyy" , CultureInfo.InvariantCulture);
- }
- if (fc[ "ReleavingDate" ] == nothing || fc[ "ReleavingDate" ] == "" )
- {
- UserReleaveDate = Catechumen.ToDateTime(goose egg );
- }
- else
- {
- UserReleaveDate = DateTime.ParseExact(fc["ReleavingDate" ], "MM/dd/yyyy" , CultureInfo.InvariantCulture);
- }
- UserNewAdd.DOB = UserDOB;
- UserNewAdd.JoiningDate = UserJoinDate;
- UserNewAdd.IsActive =simulated ;
- UserNewAdd.RoleName = _dataContext.usr_Roles.Where(s = > s.RoleID == UserNewAdd.RoleID).SingleOrDefault().RoleName;
-
- _dataContext.usr_Users.InsertOnSubmit(UserNewAdd);
-
- usr_Address AddAddressDetail =new usr_Address();
- AddAddressDetail.AddressID = Guid.NewGuid();
- AddAddressDetail.StreetOne = UserNewAdd.usrAddressList.StreetOne;
- AddAddressDetail.StreetTwo = UserNewAdd.usrAddressList.StreetTwo;
- AddAddressDetail.Landmark = UserNewAdd.usrAddressList.Landmark;
- AddAddressDetail.Urban center = UserNewAdd.usrAddressList.Urban center;
- AddAddressDetail.State = UserNewAdd.usrAddressList.Country;
- AddAddressDetail.Country = UserNewAdd.usrAddressList.Country;
- AddAddressDetail.UserID = UserNewAdd.UserID;
- AddAddressDetail.AddressType ="Primary Address" ;
- _dataContext.usr_Address.InsertOnSubmit(AddAddressDetail);
- _dataContext.SubmitChanges();
- if (UserNewAdd.usrAddressList.isper == true )
- {
- usr_Address PerAdress =new usr_Address();
- PerAdress.AddressID = Guid.NewGuid();
- PerAdress.StreetOne = UserNewAdd.usrAddressList.streatone1;
- PerAdress.StreetTwo = UserNewAdd.usrAddressList.steattwo1;
- PerAdress.Landmark = UserNewAdd.usrAddressList.landmark1;
- PerAdress.City = UserNewAdd.usrAddressList.city1;
- PerAdress.State = UserNewAdd.usrAddressList.state1;
- PerAdress.State = UserNewAdd.usrAddressList.country1;
- PerAdress.UserID = UserNewAdd.UserID;
- PerAdress.AddressType ="Permanent Accost" ;
- _dataContext.usr_Address.InsertOnSubmit(PerAdress);
- _dataContext.SubmitChanges();
- }
-
- string strLink = Catechumen.ToString(ConfigurationSettings.AppSettings[ "ApplicationPath" ]) + "/Login/Login?UserID=" + EncryptionedString(UserNewAdd.UserID.ToString());
-
- Cord msg = SendEmailWithPasswordKey(UserNewAdd.FirstName +" " + UserNewAdd.LastName, UserNewAdd.EmailID, Password, strLink);
-
- return RedirectToAction( "EmployeeList" );
- }
Step 7: Now you lot can run project. And Select profile picture field. Select Image push. So yous tin select information technology into our Drive merely.
Step 8: If yous tin have new photo from camera so you lot can select Upload from photographic camera push button.(for this piece of work only if camera supported devise like laptop and mobile)
Step 9: Ask for Shared selected device.
Pace 10: And then camera start and Take moving picture to push last button on correct side.
Step 11: If y'all tin take picture it display in profile picture paradigm in form.
0 Response to "How to Upload Image From Camera in Wpf"
Post a Comment