Click here to Skip to main content
15,891,513 members
Home / Discussions / C#
   

C#

 
AnswerRe: how to show images from server image's path to crystal report using c# application ? Pin
Richard MacCutchan2-Mar-17 6:49
mveRichard MacCutchan2-Mar-17 6:49 
QuestionHow to get a notification in a main thread when a child thread finished its task in c#. Pin
Hanumantappa Budihal1-Mar-17 23:37
professionalHanumantappa Budihal1-Mar-17 23:37 
AnswerRe: How to get a notification in a main thread when a child thread finished its task in c#. Pin
Richard MacCutchan1-Mar-17 23:41
mveRichard MacCutchan1-Mar-17 23:41 
AnswerRe: How to get a notification in a main thread when a child thread finished its task in c#. Pin
OriginalGriff2-Mar-17 0:09
mveOriginalGriff2-Mar-17 0:09 
QuestionHow can I pass DataTable to view as JSON/XML code? Pin
Member 1079645326-Feb-17 23:34
Member 1079645326-Feb-17 23:34 
SuggestionRe: How can I pass DataTable to view as JSON/XML code? Pin
Richard MacCutchan27-Feb-17 0:30
mveRichard MacCutchan27-Feb-17 0:30 
AnswerRe: How can I pass DataTable to view as JSON/XML code? Pin
F-ES Sitecore28-Feb-17 3:08
professionalF-ES Sitecore28-Feb-17 3:08 
QuestionImage upload error javascript/c# Pin
John Nederveen26-Feb-17 3:00
John Nederveen26-Feb-17 3:00 
Hello best codeproject members,
I have a problem that i can not resolve. I hope someone can get me on the right 'code' I have implant to my code a 'javascript' (there was already a input file for a url, but i decided to add also a file upload button), wenn i go to the site and 'create a new message' and try to upload the file it gives me a 'image not suported error'. Here is a part of the script;

Thank you


The Div;
HTML
<div class="form-group">
    <input type="file" class="btn btn-default btn-file" style="width:70%" id="file" name="file" />
    <input type="button" value="Upload" class="btn btn-primary uploadbtn" id="uploadimg" name="upladimage" />
    <img class="wait hide" id="wait" src="/Content/img/pleasewait .gif" />
    You can upload the only image file.
</div>


The Javascript;
JavaScript
$("#imgurl").keyup(
                function () {
                    $("#pmainimg").attr("src", $("#imgurl").val());
                });
 //$('#file').on('change', function (e) {
        //    files= $(this).get(0).files[0];
        //    alert(files);
        //});

        $(document).on('click', '#uploadimg', function () {

            if (window.FormData !== undefined) {
                var fileUpload = $("#file").get(0);
                var files = fileUpload.files;
                // Create FormData object
                var fileData = new FormData();

                // Looping over all files and add it to FormData object


                // Adding one more key to FormData object
                if ($("#file").val()!='') {
                    fileData.append(files[0].name, files[0]);

                    $("#wait").removeClass("hide");
                    $("#wait").addClass("show");
                    $.ajax({
                        url: '/Member/UploadImage',
                        type: "POST",
                        contentType: false, // Not to set any content header
                        processData: false, // Not to process data
                        data: fileData,
                        success: function (result) {
                            if (result.indexOf("http") > -1) {
                                $("#imgurl").val(result);
                                $("#pmainimg").attr("src", $("#imgurl").val());
                                $("#wait").removeClass("show");
                                $("#wait").addClass("hide");
                            }
                            else {
                                debugger;

                                $("#errormsg").html("You can upload the only image file.");
                                $("#errormsg").css("display", "inline");
                                $("#errormsg").css("color", "red");

                                $("#wait").removeClass("show");
                                $("#wait").addClass("hide");
                            }
                            // alert(result);

                        },
                        error: function (err) {
                            alert("Image Not Supported");
                            $("#wait").removeClass("show");
                            $("#wait").addClass("hide");
                        }
                    });
                }
                else
                {
                    $("#errormsg").html("You have not specified a image file.");
                    $("#errormsg").css("display", "inline");
                    $("#errormsg").css("color", "red");
                    $("#wait").removeClass("show");
                    $("#wait").addClass("hide");

                }
            } else {
                alert("FormData is not supported.");
            }
        });


Controler;
C#
{    
[UserLoginRequired]
    public class MemberController : ClickMSGController
    {
        public ActionResult CreateMessage()
        {
            return View();
        }

        public ExpandoObject CreateMessageObject(string ctatitle, string msgtitle, string msgbody, string imgurl,
            string linkurl, string linktxt, string reply1, string reply2, string msgname)
        {
            //Construct the JSON Object, from the inner levels towards the outer
            dynamic button1 = new ExpandoObject();
            button1.type = "web_url";
            button1.url = linkurl;
            button1.title = linktxt;

            dynamic button2 = new ExpandoObject();
            button2.type = "postback";
            button2.title = ctatitle;
            button2.payload = Guid.NewGuid().ToString();

            dynamic element = new ExpandoObject();
            element.title = msgtitle;
            element.image_url = imgurl;
            element.subtitle = msgbody;
            element.buttons = new List<object> { button1, button2 };

            dynamic payload = new ExpandoObject();
            payload.template_type = "generic";
            payload.elements = new List<object> { element };

            dynamic attachment = new ExpandoObject();
            attachment.type = "template";
            attachment.payload = payload;

            dynamic message = new ExpandoObject();
            message.attachment = attachment;

            dynamic fbmsg = new ExpandoObject();
            fbmsg.message = message;

            if (!string.IsNullOrEmpty(reply1) && !string.IsNullOrEmpty(reply2))
            {
                //Replies
                dynamic reply1obj = new ExpandoObject();
                reply1obj.content_type = "text";
                reply1obj.title = reply1;
                reply1obj.payload = reply1;

                dynamic reply2obj = new ExpandoObject();
                reply2obj.content_type = "text";
                reply2obj.title = reply2;
                reply2obj.payload = reply2;

                fbmsg.message.quick_replies = new List<object> { reply1obj, reply2obj };
            }

            return fbmsg;
        }

        public ActionResult GetJson(string ctatitle, string msgtitle, string msgbody, string imgurl,
            string linkurl, string linktxt, string reply1, string reply2, string msgname)
        {
            ExpandoObject msgObject = CreateMessageObject(ctatitle, msgtitle, msgbody, imgurl, linkurl, linktxt, reply1, reply2, msgname);

            if (Request.Form["savebtn"] == "Save & Get JSON")
            {
                AdManager.Ad ad = new AdManager.Ad();
                ad.AdName = msgname;
                ad.CallToAction = ctatitle;
                ad.Image_URL = imgurl;
                ad.LinkButtonText = linktxt;
                ad.LinkButtonURL = linkurl;
                ad.Reply1 = reply1;
                ad.Reply2 = reply2;
                ad.Subtitle = msgbody;
                ad.Title = msgtitle;
                ad.UserID = CurrentUser.ID;

                AdManager.AddAd(ad);
            }
            ViewBag.Json = Newtonsoft.Json.JsonConvert.SerializeObject(msgObject);

            return View("result");
        }

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

        public ActionResult ManageMessages()
        {
            List<AdManager.Ad> ads  = AdManager.GetAdsForUser(CurrentUser.ID);
            ViewBag.Ads = ads;

            return View();
        }

        public ActionResult EditAd(int ad)
        {
            AdManager.Ad adv = AdManager.GetAd(ad);
            ViewBag.Ad = adv;

            return View();
        }

        [HttpPost]
        public ActionResult UpdateAd(string ctatitle, string msgtitle, string msgbody, string imgurl,
       string linkurl, string linktxt, string reply1, string reply2, string msgname,int adid)
        {
            ExpandoObject msgObject = CreateMessageObject(ctatitle, msgtitle, msgbody, imgurl, linkurl, linktxt, reply1, reply2, msgname);

            AdManager.Ad ad = new AdManager.Ad();
            ad.AdName = msgname;
            ad.CallToAction = ctatitle;
            ad.Image_URL = imgurl;
            ad.LinkButtonText = linktxt;
            ad.LinkButtonURL = linkurl;
            ad.Reply1 = reply1;
            ad.Reply2 = reply2;
            ad.Subtitle = msgbody;
            ad.Title = msgtitle;
            ad.UserID = CurrentUser.ID;
            ad.ID = adid;

            AdManager.UpdateAd(ad);

            ViewBag.Json = Newtonsoft.Json.JsonConvert.SerializeObject(msgObject);

            return View("result");
        }

        public ActionResult UpdateAd(int Ad)
        {
            ViewBag.Ad= AdManager.GetAd(Ad);
            return View();
        }

        public ActionResult Delete(int Ad)
        {
          
            ViewBag.DeletedAd = AdManager.DeleteAd(Ad);
            List<AdManager.Ad> ads = AdManager.GetAdsForUser(CurrentUser.ID);
            ViewBag.Ads = ads;
            return View("ManageMessages");
        }

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

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

AnswerRe: Image upload error javascript/c# Pin
Richard Deeming26-Feb-17 5:33
mveRichard Deeming26-Feb-17 5:33 
GeneralRe: Image upload error javascript/c# Pin
John Nederveen26-Feb-17 8:15
John Nederveen26-Feb-17 8:15 
GeneralRe: Image upload error javascript/c# Pin
Dave Kreskowiak26-Feb-17 8:30
mveDave Kreskowiak26-Feb-17 8:30 
GeneralRe: Image upload error javascript/c# Pin
John Nederveen26-Feb-17 9:05
John Nederveen26-Feb-17 9:05 
GeneralRe: Image upload error javascript/c# Pin
Dave Kreskowiak26-Feb-17 10:48
mveDave Kreskowiak26-Feb-17 10:48 
QuestionWMI Events can't get User | ManagementEventWatcher, __INstanceCreationEvent, Win32_Process GetOwner Pin
Member 1302224424-Feb-17 10:25
Member 1302224424-Feb-17 10:25 
AnswerRe: WMI Events can't get User | ManagementEventWatcher, __INstanceCreationEvent, Win32_Process GetOwner Pin
Michael_Davies24-Feb-17 10:37
Michael_Davies24-Feb-17 10:37 
GeneralRe: WMI Events can't get User | ManagementEventWatcher, __INstanceCreationEvent, Win32_Process GetOwner Pin
Member 1302224424-Feb-17 16:02
Member 1302224424-Feb-17 16:02 
QuestionHow to customize timer to fire my routine at specific time Pin
Tridip Bhattacharjee23-Feb-17 22:33
professionalTridip Bhattacharjee23-Feb-17 22:33 
AnswerRe: How to customize timer to fire my routine at specific time Pin
Pete O'Hanlon23-Feb-17 22:42
mvePete O'Hanlon23-Feb-17 22:42 
AnswerRe: How to customize timer to fire my routine at specific time Pin
OriginalGriff23-Feb-17 22:46
mveOriginalGriff23-Feb-17 22:46 
GeneralRe: How to customize timer to fire my routine at specific time Pin
Tridip Bhattacharjee23-Feb-17 22:50
professionalTridip Bhattacharjee23-Feb-17 22:50 
GeneralRe: How to customize timer to fire my routine at specific time Pin
OriginalGriff23-Feb-17 23:01
mveOriginalGriff23-Feb-17 23:01 
AnswerRe: How to customize timer to fire my routine at specific time Pin
Ralf Meier24-Feb-17 0:16
mveRalf Meier24-Feb-17 0:16 
QuestionInserting Localised Lookup Data into a Fresh Database Pin
Jammer23-Feb-17 8:16
Jammer23-Feb-17 8:16 
AnswerRe: Inserting Localised Lookup Data into a Fresh Database Pin
Gerry Schmitz23-Feb-17 9:53
mveGerry Schmitz23-Feb-17 9:53 
GeneralRe: Inserting Localised Lookup Data into a Fresh Database Pin
Jammer23-Feb-17 10:16
Jammer23-Feb-17 10:16 

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.