Skip to content

File Upload MVC Razor

<html>

<head>

<title>Index</title>

</head>

<body>

<div>

<h2>Upload File</h2>

<form method="post" enctype="multipart/form-data">

<label>Filename: <input type="file" name="file" /></label>

<input type="submit" value="Submit" />

</form>

</div>

</body>

</html>

After adding a control in view adds the following code in the controller to upload the file on the server:

using System.Web.Mvc;

using System.IO;

using System.Web;

namespace FileUploadDemo.Controllers

{

public class HomeController : Controller

{

public ActionResult Index()

{

return View();

}

[HttpPost]

public ActionResult Index(HttpPostedFileBase file)

{

var fileName = Path.GetFileName(file.FileName);

if (fileName != null)

file.SaveAs(Server.MapPath("~\\files\\" + fileName));

return View();

}

}

}

Advertisements

Visual Studio to Debug JavaScript in IE

http://www.codeproject.com/Articles/18921/Using-Visual-Studio-to-Debug-JavaScript-in-IE

http://www.guidanceshare.com/wiki/Main_Page

http://www.guidanceshare.com/wiki/Main_Page

Code First with Entity Framework 5 using MVC4 and MVC Scaffold

http://www.codeproject.com/Articles/468777/Code-First-with-Entity-Framework-5-using-MVC4-and#

TSQL Paging schnell

 

DECLARE @PageNum AS INT;
DECLARE @PageSize AS INT;
SET @PageSize = 10;
SET @PageNum = 1;

WITH Products AS
(
    SELECT *, ROW_NUMBER() OVER(ORDER BY lngProductID) AS RowNum     
      FROM tblProduct
)

SELECT *
  FROM Products
WHERE RowNum BETWEEN (@PageNum – 1) * @PageSize + 1
                  AND @PageNum * @PageSize
ORDER BY lngProductID;

Paging Langsam 2 sec.

— Set the page bounds
    DECLARE @PageLowerBound int
    DECLARE @PageUpperBound int
    DECLARE @TotalRecords   int
    DECLARE @PageSize   int
    DECLARE @PageIndex   int
   
    SET @PageSize = 10
    SET @PageIndex = 0
       
    SET @PageLowerBound = @PageSize * @PageIndex
    SET @PageUpperBound = @PageSize – 1 + @PageLowerBound

    — Create a temp table TO store the select results
    CREATE TABLE #PageIndexForProducts
    (
        IndexId int IDENTITY (0, 1) NOT NULL,
        ProductId int
    )
   
     INSERT INTO #PageIndexForProducts (ProductID)
            SELECT p.lngProductID
            FROM   tblProduct p
            ORDER BY p.lngProductID
      
select * from tblProduct p inner join #PageIndexForProducts i
    on p.lngProductID = i.ProductId   
    where i.IndexId >= @PageLowerBound and i.IndexId <= @PageUpperBound            
           
–SELECT  @TotalRecords = COUNT(*)
–    FROM    #PageIndexForProducts
–    RETURN @TotalRecords
              
Drop TABLE #PageIndexForProducts

handling-concurrency-with-the-entity-framework

http://www.asp.net/web-forms/tutorials/continuing-with-ef/handling-concurrency-with-the-entity-framework-in-an-asp-net-web-application