Click here to Skip to main content
15,887,910 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: IE version problem Pin
parthi_src21-Jun-16 7:05
parthi_src21-Jun-16 7:05 
AnswerRe: IE version problem Pin
John C Rayan20-Jun-16 1:48
professionalJohn C Rayan20-Jun-16 1:48 
GeneralRe: IE version problem Pin
parthi_src21-Jun-16 7:06
parthi_src21-Jun-16 7:06 
GeneralRe: IE version problem Pin
John C Rayan22-Jun-16 1:33
professionalJohn C Rayan22-Jun-16 1:33 
GeneralRe: IE version problem Pin
parthi_src22-Jun-16 7:00
parthi_src22-Jun-16 7:00 
GeneralRe: IE version problem Pin
John C Rayan23-Jun-16 4:00
professionalJohn C Rayan23-Jun-16 4:00 
QuestionHow to trigger an event from fileupload? Pin
turbosupramk316-Jun-16 6:25
turbosupramk316-Jun-16 6:25 
AnswerRe: How to trigger an event from fileupload? Pin
jkirkerx16-Jun-16 8:02
professionaljkirkerx16-Jun-16 8:02 
To the best of my knowledge, you just listen for the file upload event.

In MVC, I wrote a new way of uploading a file, or multiple files at the same time.
I used JQuery to listen for the DOM event "change"; file upload button, and ran a JQuery function to intercept the upload and target the data to a JsonResult in one of my controllers, an Ajax controller.

Sounds weird huh?. But I will show 2 examples, MVC and Webforms. I believe this is the secret to Uploadify.

JQuery: in the document ready, I listened for the upload button to fire an event to upload the file stream, which is just a base64 string representing bytes. So this validates the name of the files, and then runs the function
$("#AvatarBrowse").on("change", function (e) {
    if (validate_upload_brandAvatar()) {
        run_upload_brandAvatar(e, $(this));
    }
});
JQuery: This intercepts the file upload, but passes extra data along with the page event.
var _extraData = "?id=-1&avatarName=" + _avatarName + "&avatarAlt=" + _avatarAlt;

if (window.FormData !== undefined) {
    var _data = new FormData();
    for (var x = 0; x < _files.length; x++) {
        _data.append("file" + x, _files[x]);
    }

    $.ajax({
        type: "POST",
        url: '/Ajax/json_upload_brand_avatar' + _extraData,
        contentType: false,
        processData: false,
        data: _data,
Then in my Ajax Controller, its an Async Task<<JsonResult>>
This grabs the file content in the base64 string of bytes, and converts the string to a byte array to save in the database. Then it processes the image, and sends back a base64 string of the image to preview after changes.
var fileContent = Request.Files[file];
      if (fileContent != null && fileContent.ContentLength > 0)
      {
           // Wait and convert the Stream to a Byte Array
           using (MemoryStream stream_in = new MemoryStream())
           {
              fileContent.InputStream.CopyTo(stream_in);

              // and optionally write the file to disk
              string oFileName = fileContent.FileName;
              string oFileExt = Path.GetExtension(oFileName);
              string fileName = cleanInput.Clean_FileName(avatarName.ToLower() + oFileExt);
              var path = Path.Combine(Server.MapPath("~/Images/avatars/departments"), fileName);

On webforms, it's a different process.
you use the IHTTPHandler and ProcessRequest to intercept the file upload. I wrote this in VB, I just started writing in c#. This uses uploadify to upload the file, and the function below intercepts the upload from the browser, captures the post to the server.
Public Class Admin_Management_ckEditor_Upload
    Inherits System.Web.UI.Page
    Implements IHttpHandler
    Implements IRequiresSessionState

    Public Overrides Sub ProcessRequest(ByVal context As HttpContext)

        Dim Exception_Message As String = Nothing

        Try

            Dim vFlag As Boolean = False

            Dim m_Context As HttpContext = HttpContext.Current
            Dim m_file As HttpPostedFile = m_Context.Request.Files("upload")

            If Not (m_file Is Nothing) Then

                'Get the Uploaded file information from the file object
                Dim m_fileName As String = m_file.FileName
                Dim m_fileSize As Integer = m_file.ContentLength
                Dim m_fileContent As String = m_file.ContentType

Basically in a nut shell, the browser will post the file to the server, you just need something to intercept the post and do something with it. I find once again that MVC is much more easier to work with and requires much less code.

Knowing now that the upload is just a base64 string of bytes, it's much easier for me to comprehend what is happening, and turn that string of bytes into a byte array to save in the database or to write out as a file. I choose to funnel that byte array into an image processor that I wrote, posted in a previous post here, to further process the image and return the byte array back, using my Ajax controller function. I sent it back as a base64 string to the page so the processed image can be previewed and saved.

I don't expect you to just pick on this and run with it, but its enough information for you to search in the right direction towards your goal. I don't remember a simpler way of doing it anymore. It's one of those things that you write once and keep using over and over.
AnswerRe: How to trigger an event from fileupload? Pin
F-ES Sitecore17-Jun-16 1:49
professionalF-ES Sitecore17-Jun-16 1:49 
QuestionReg Chorome Browser Pin
harikreddy16-Jun-16 2:29
harikreddy16-Jun-16 2:29 
AnswerRe: Reg Chorome Browser Pin
Nathan Minier17-Jun-16 1:47
professionalNathan Minier17-Jun-16 1:47 
AnswerRe: Reg Chorome Browser Pin
F-ES Sitecore17-Jun-16 1:51
professionalF-ES Sitecore17-Jun-16 1:51 
AnswerRe: Reg Chorome Browser Pin
John C Rayan20-Jun-16 1:53
professionalJohn C Rayan20-Jun-16 1:53 
Questionhow to get latitude and logitude from sql server Asp.net WEBForm Pin
Member 1180506316-Jun-16 1:03
Member 1180506316-Jun-16 1:03 
AnswerRe: how to get latitude and logitude from sql server Asp.net WEBForm Pin
Member 1180506317-Jun-16 1:56
Member 1180506317-Jun-16 1:56 
QuestionBad Behavior Pin
BobbyStrain15-Jun-16 9:35
BobbyStrain15-Jun-16 9:35 
AnswerRe: Bad Behavior Pin
jkirkerx15-Jun-16 10:18
professionaljkirkerx15-Jun-16 10:18 
GeneralRe: Bad Behavior Pin
BobbyStrain15-Jun-16 12:44
BobbyStrain15-Jun-16 12:44 
GeneralRe: Bad Behavior Pin
Nathan Minier16-Jun-16 1:18
professionalNathan Minier16-Jun-16 1:18 
GeneralRe: Bad Behavior Pin
BobbyStrain16-Jun-16 6:24
BobbyStrain16-Jun-16 6:24 
GeneralRe: Bad Behavior Pin
Nathan Minier17-Jun-16 1:57
professionalNathan Minier17-Jun-16 1:57 
GeneralRe: Bad Behavior Pin
BobbyStrain17-Jun-16 5:50
BobbyStrain17-Jun-16 5:50 
Question@Url is saying "the name url doesn't exist in the current context" ASP.MVC 4 Pin
indian14314-Jun-16 10:02
indian14314-Jun-16 10:02 
AnswerRe: @Url is saying "the name url doesn't exist in the current context" ASP.MVC 4 Pin
jkirkerx15-Jun-16 7:24
professionaljkirkerx15-Jun-16 7:24 
GeneralRe: @Url is saying "the name url doesn't exist in the current context" ASP.MVC 4 Pin
indian14315-Jun-16 8:06
indian14315-Jun-16 8:06 

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.