Click here to Skip to main content
12,819,619 members (34,054 online)
Rate this:
Please Sign up or sign in to vote.
I want to send a message to another member of a web application.

Message will contain text and as well as attachment of images or pdf.

I have used message sending $.ajax post of JQuery with XML WebService.

Everything is okay but I cannot sent Image object with this message.
Is there anyway to save image with the message in same function?

$("#btnSend").click(function (evt) {

    if (validateMSG()) {
        var mailMsg = { From: clientId, To: parseInt(msgTo), Subject: Subject, Body: body }

            url: "/StuffProfile.asmx/SendMessage",
            data: JSON.stringify({ mailMsg: mailMsg }),
            dataType: "json",
            type: "POST",
            async: true,
            cache: false,
            contentType: "application/json; charset=utf-8",
            success: function (result) {
                res = $.parseJSON(result.d);
                jAlert(res.MSG, "Success");
                //var obj = { type: 2, LASTMAILID: res.MSGID };
                GetNewMailMesseges(2, res.MSGID - 1);
            error: function () { jAlert("Error Occured", "Error"); },
            complete: function () {

function validateMSG()
    var msgTo = $("#staff-id").val();
    if (!msgTo) { jAlert("Select a Staff or Send to Please", "Error", function () { $("#txtTo").focus(); return false; }); }
    else return true;
    var Subject = $("#txtSubject").val();
    if (Subject == '') { jAlert("Add Subject Please", "Error", function () { $("#txtSubject").focus(); return false; }) }
    else return true;
    var body = $(".editor").val();
    if (!body) { jAlert("You cannot send empty message."); $(".editor").focus(); return false; }
    else return true;

I want to send Image or any file with it.

/// <summary>
       /// Send Mail Message
       /// </summary>
       /// <param name="mailMsg">Wooskie.Business.Mail Object </param>
       /// <returns>Success Message</returns>
       [ScriptMethod(ResponseFormat = ResponseFormat.Json, XmlSerializeString = true)]
       public string SendMessage( Mail mailMsg )
           mailMsg.Read = false;
           mailMsg.Status = "sent";
           mailMsg.Date = DateTime.UtcNow;
               var db = new WooskieDBInstance().WooskieDB;
               var mailID = mailMsg.ID;
               return  new JavaScriptSerializer().Serialize(new { MSG = "Mail Send Successfully.",MSGID=mailID });
           catch (Exception ex)
               return ex.Message;

<div id="compose" class="mail ui-widget">
        <img title="Close" alt="X" src="../Images/close-button.png" id="compose-close">
        <div class="compose ui-widget">
            <input type="text" role="textbox" class="txt-to margin-left" id="txtTo"
                required="required" placeholder="Send To" style="width: 100%" />
            <input type="hidden" id="staff-id" />

            <br />
            <input type="text" role="textbox" class="txt-subject margin-left" style="width: 100%" id="txtSubject" required="required" placeholder="Subject" />
            <br />
            <br />
            <asp:Label ID="Label3" runat="server" Text="Message" meta:resourcekey="Label3Resource1"></asp:Label>

            <textarea class="editor"></textarea>
            <script src="../ckeditor/ckeditor.js"></script>
            <script src="../ckeditor/adapters/jquery.js"></script>
            <script type="text/javascript">
            <br />
            <br />
                <asp:FileUpload ID="fileToUpload" runat="server"   ClientIDMode="Static" meta:resourcekey="attachmentResource1"  Font-Size="9px" Width="100%" />


Please help me.
Posted 19-Dec-12 11:45am
Updated 19-Dec-12 12:35pm
Christian Graus 19-Dec-12 17:20pm
Is that REALLY your name ? Aren't you dead ?
Yaseer Arafat 19-Dec-12 17:24pm
Yes.This is my real name.And you have found me alive and asking for help.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can't send an image. javascript does not have the ability to read the file system. You can only send an image to the server via a submitted form with a file input control on it. You also cannot resize an image with javascript. Nothing about your question makes sense to me. Why is the image resized ? The only way to 'send a message' is for your database to record it, and the other member to refresh their web page in order to see it.
Yaseer Arafat 19-Dec-12 17:22pm
Other member dose not need to refresh page.Because I have use setInterval function for fetching messages.
Christian Graus 19-Dec-12 17:24pm
Yes, you can make your page keep asking, without a refresh. But you can't push out to the page, was my point. Your question still makes no sense to me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170308.1 | Last Updated 19 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100