Reputation: 13
I upload a Html file with Dropzone.js, as into site examples :
//Upload view
@using System.Text;
@{
Layout = null;
string path = ViewBag.path;
}
@if (String.IsNullOrEmpty(fileName))
{
@Styles.Render("~/Content/css")
@Styles.Render("~/Content/themes/base/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")
@Scripts.Render("~/bundles/bootstrap")
@Scripts.Render("~/bundles/dropzone")
<form action="@Url.Action("Upload", "Home")" class="dropzone" id="dropzoneJsForm"></form>
<button id="submit-all">Submit All Files</button>
<script type="text/javascript">
Dropzone.options.dropzoneJsForm = {
//prevents Dropzone from uploading dropped files immediately
autoProcessQueue: false,
init: function () {
var submitButton = document.querySelector("#submit-all");
var myDropzone = this; //closure
submitButton.addEventListener("click", function () {
//tell Dropzone to process all queued files
myDropzone.processQueue();
});
}
};
</script>
}
else
{
@Html.Raw(System.Web.HttpUtility.HtmlEncode(File.ReadAllText(path)))
}
//HomeController
public ActionResult Upload()
{
foreach (string fileName in Request.Files)
{
HttpPostedFileBase file = Request.Files[fileName];
if (file.ContentLength > 0)
{
var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
file.SaveAs(path);
ViewBag.path = path;
}
}
return View();
}
The file was saved,the view can read it but the page did not display anything. I can not figure out what's not working. If I active the debugger seems that everything is ok but in the end the page did not draw the html tag of the file. Can you help me or suggest a possible solution
Thank you so much
Upvotes: 0
Views: 2306
Reputation: 731
Instead HttpUtility.HtmlDecode, can you please check HttpUtility.UrlDecode, assuming your file is pure html, not html characters.
Upvotes: 2