Click here to Skip to main content
15,886,258 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: The reference assemblies for framework ".NETFramework,Version=v4.6.2" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the Pin
Mycroft Holmes23-Jan-19 14:42
professionalMycroft Holmes23-Jan-19 14:42 
GeneralRe: The reference assemblies for framework ".NETFramework,Version=v4.6.2" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the Pin
simpledeveloper23-Jan-19 16:55
simpledeveloper23-Jan-19 16:55 
GeneralRe: The reference assemblies for framework ".NETFramework,Version=v4.6.2" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the Pin
simpledeveloper23-Jan-19 17:36
simpledeveloper23-Jan-19 17:36 
GeneralRe: The reference assemblies for framework ".NETFramework,Version=v4.6.2" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the Pin
Nelek23-Jan-19 19:05
protectorNelek23-Jan-19 19:05 
QuestionOn web form button, prevent user from clicking the button more than 1 time Pin
dcof17-Jan-19 5:10
dcof17-Jan-19 5:10 
AnswerRe: On web form button, prevent user from clicking the button more than 1 time Pin
Richard MacCutchan17-Jan-19 5:20
mveRichard MacCutchan17-Jan-19 5:20 
Questionhow to Import Excel file into Data base using Entityframework in MVC Pin
Member 1408535316-Jan-19 17:55
Member 1408535316-Jan-19 17:55 
AnswerRe: how to Import Excel file into Data base using Entityframework in MVC Pin
Member 1408535316-Jan-19 18:03
Member 1408535316-Jan-19 18:03 
Make a .CS file with name of ImportExcel.CS
:----
public class FileExt : ValidationAttribute
    {
        public string Allow;
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (value != null)
            {
                string extension = ((System.Web.HttpPostedFileBase)value).FileName.Split('.')[1];
                if (Allow.Contains(extension))
                    return ValidationResult.Success;
                else
                    return new ValidationResult(ErrorMessage);
            }
            else
                return ValidationResult.Success;
        }
    }

    public class ImportExcel
    {
        [Required(ErrorMessage = "Please select file")]
        [FileExt(Allow = ".xls,.xlsx", ErrorMessage = "Only excel file")]
        public HttpPostedFileBase file { get; set; }
    }



And Add this code to your controller
:-----

public ActionResult ImportExcel()
       {
           return View();
       }

       [HttpPost]
       public ActionResult importexcel(ImportExcel importExcel)
       {
           if (ModelState.IsValid)
           {
               string path = Server.MapPath("~/library/ExcelFile/" + importExcel.file.FileName);
               importExcel.file.SaveAs(path);

               string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source='" + path + "';Extended Properties='Excel 12.0;'";
               OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);

               //Sheet Name
               excelConnection.Open();
               string tableName = excelConnection.GetSchema("Tables").Rows[0]["TABLE_NAME"].ToString();
               excelConnection.Close();
               //End

               OleDbCommand cmd = new OleDbCommand("Select * from [" + tableName + "]", excelConnection);

               excelConnection.Open();

               OleDbDataReader dReader;
               dReader = cmd.ExecuteReader();
               SqlBulkCopy sqlBulk = new SqlBulkCopy(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);

               //Give your Destination table name
               sqlBulk.DestinationTableName = "ExcelFile";

               //Mappings
               sqlBulk.ColumnMappings.Add("Userid", "Userid");
               sqlBulk.ColumnMappings.Add("Name", "Name");
               sqlBulk.ColumnMappings.Add("TelephoneNo", "TelephoneNo");
               sqlBulk.ColumnMappings.Add("Address", "Address");
               sqlBulk.ColumnMappings.Add("EmailAddress", "EmailAddress");


               sqlBulk.WriteToServer(dReader);
               excelConnection.Close();

               ViewBag.Result = "Successfully Imported";
           }
           return View();
       }





And create view page of ImportExcel method with name of ImportExcel.cshtml and add this code
:-----



@model Models.GeneralModel.ImportExcel



<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>ImportExcel</title>
</head>
<body>
    <div style="float:right"> 
        <h4>@ViewBag.Result</h4>
        @using (Html.BeginForm("ImportExcel", "NewCustomer", FormMethod.Post, new { enctype = "multipart/form-data" }))
        {
            @Html.TextBoxFor(m => m.file, new { type = "file" })
            <button id="submitButton" type="submit">Submit</button>
            @Html.ValidationMessageFor(model => model.file)
        }
    </div>
</body>
</html>




Thumbs Up | :thumbsup:
GeneralRe: how to Import Excel file into Data base using Entityframework in MVC Pin
Richard Deeming17-Jan-19 1:52
mveRichard Deeming17-Jan-19 1:52 
QuestionASP.Net code won't run Pin
Member 1406015916-Jan-19 11:43
Member 1406015916-Jan-19 11:43 
AnswerRe: ASP.Net code won't run Pin
F-ES Sitecore17-Jan-19 0:15
professionalF-ES Sitecore17-Jan-19 0:15 
QuestionAn exception of type 'System.Data.Entity.Core.EntityException' occurred in EntityFramework.SqlServer.dll but was not handled in user code Pin
RedPandinus15-Jan-19 12:34
RedPandinus15-Jan-19 12:34 
AnswerRe: An exception of type 'System.Data.Entity.Core.EntityException' occurred in EntityFramework.SqlServer.dll but was not handled in user code Pin
Richard Deeming16-Jan-19 8:12
mveRichard Deeming16-Jan-19 8:12 
QuestionImport Tabulor form data from PDF file Pin
Member 1411436712-Jan-19 20:34
Member 1411436712-Jan-19 20:34 
AnswerRe: Import Tabulor form data from PDF file Pin
Richard MacCutchan12-Jan-19 22:54
mveRichard MacCutchan12-Jan-19 22:54 
GeneralRe: Import Tabulor form data from PDF file Pin
Member 1411436714-Jan-19 1:13
Member 1411436714-Jan-19 1:13 
GeneralRe: Import Tabulor form data from PDF file Pin
Richard MacCutchan14-Jan-19 1:46
mveRichard MacCutchan14-Jan-19 1:46 
GeneralRe: Import Tabulor form data from PDF file Pin
Nitin S25-Jan-19 1:40
professionalNitin S25-Jan-19 1:40 
QuestionWhat layers required for make asp.net core 2 project for prevent repeat data ? Pin
ahmed_sa2-Jan-19 21:53
ahmed_sa2-Jan-19 21:53 
AnswerRe: What layers required for make asp.net core 2 project for prevent repeat data ? Pin
Richard MacCutchan2-Jan-19 23:37
mveRichard MacCutchan2-Jan-19 23:37 
AnswerRe: What layers required for make asp.net core 2 project for prevent repeat data ? Pin
Vincent Maverick Durano3-Jan-19 22:35
professionalVincent Maverick Durano3-Jan-19 22:35 
AnswerRe: What layers required for make asp.net core 2 project for prevent repeat data ? Pin
James Walsh Jr12-Jan-19 5:47
professionalJames Walsh Jr12-Jan-19 5:47 
QuestionLossless Image compression Pin
Member 141024622-Jan-19 8:37
Member 141024622-Jan-19 8:37 
AnswerRe: Lossless Image compression Pin
Richard MacCutchan3-Jan-19 1:18
mveRichard MacCutchan3-Jan-19 1:18 
QuestionIs there any data mocking for calling Web API Put and post methods with C# Code Pin
simpledeveloper25-Dec-18 12:55
simpledeveloper25-Dec-18 12:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.