|
Hi all, I have a web page that allows users to drag an image from their desktop on to a box that had been designated as a droppable box. Once the image is dropped it will be sent to a web service to be saved in a folder on the server. The following is the Javascript I'm using to send the image from the frontend to the webservice.
function ImageUpload(file) {
xhr = new XMLHttpRequest();
xhr.open('post', 'SaveImageService.asmx', true);
xhr.setRequestHeader('Content-Type', "multipart/form-Data");
xhr.setRequestHeader('X-File-Name', file.fileName);
xhr.setRequestHeader('X-File-Size', file.fileSize);
xhr.setRequestHeader('X-File-type', file.fileType);
xhr.send(file);
};
I am using the following code in my web service to save the posted image in a folder called Images. I'm not certain if the project folder name should be included as part of the folder path when I specify where to save the uploaded images. I tried including and excluding the project folder name but it didn't help.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
namespace ImageUpload
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class SaveImageService : System.Web.Services.WebService
{
[WebMethod]
public void SaveImage()
{
var httpRequest = HttpContext.Current.Request;
foreach (string file in httpRequest.Files)
{
var postedFile = httpRequest.Files[file];
var filePath = HttpContext.Current.Server.MapPath("~/Images/" + postedFile.FileName);
postedFile.SaveAs(filePath);
}
}
}
}
I am getting response status of 500 internal server error. Please look at the code above and point out any problem you see. Thanks in advance for your help.
modified 25-Oct-14 9:21am.
|
|
|
|
|
As you are calling this using AJAX, then do you have the SaveImageService registered in the ScriptManager control on your ASPX page?
Christopher Reed
"The oxen are slow, but the earth is patient."
|
|
|
|
|
Hi, thanks for responding. The web service is not registered in the Scriptmanager control and there is no ASXP page.
|
|
|
|
|
I think your issue is in your loop. Try:
foreach (string file in httpRequest.Files.AllKeys)
|
|
|
|
|
Hello,
I am getting an error 0xC0000006 when starting program that normally starts up and runs fine. It is being
executed from a network drive. I am working with .NET 2.0, however some machines that I am using have
the .NET 3.5 or .NET 4.0 runtime installed. The machines that are giving the errors are running Windows 7
Professional.
Any help or advice is appreciated.
|
|
|
|
|
You MUST have .NET 2.0 installed and, by default, code running from network sources is not trusted. Your code is running in a very restricted sandbox.
So, either you have to tell the machine to trust the network source, or move the .EXE to the local hard drive and run it from there. Running from a network source isn't the greatest idea if you're going to be replacing the .EXE since the file is locked when the code is running on any machine.
|
|
|
|
|
Dave,
Thank you for your response.
How do I go about telling the machine to trust the network source? Is this procedure common for all versions of Windows? (XP, Win7, Win8, Win10, etc). I don't think putting the EXE on a local drive is a good option in our case. For updates, I would have to go to every machine and update. Another vendor, which we interface with their software, they put everything on the network with no problems.
Mike
|
|
|
|
|
look for instruction/how to use 'CasPol.exe' and see if that gives you the options
Control Panel->Administrative Tools->.NET Framework Configuration ?.?->Runtime Security Policy->Adjust Zone Security might also be of some use
|
|
|
|
|
Is there something I'm misisng? I tried this and it still does not correct the problem. I had to use the caspol from the cmd line, using the guidelines seen here:
<a href="https://julianscorner.com/wiki/programming/caspol_network_share">
</a>[<a href="https://julianscorner.com/wiki/programming/caspol_network_share" target="_blank" title="New Window">^</a>]
Any other hints?
Thanks
Mike
|
|
|
|
|
|
Hello,
I am receiving an "Application has stopped working" error in my C# WinForms application. The running OS versions are Windows 7 Home Premium, Windows 7 Professional and also a few WinXP Home machines. I have an exception handler set up in my code:
public void MyExceptionHandler
(Object sender, ThreadExceptionEventArgs e)
{
MessageBox.Show("Internal Error" +
"\r\n\r\n" +
e.Exception.Message + "\r\n\r\n" +
"Stack Trace: " + e.Exception.StackTrace, "Oslermedicine® Manager Notification");
}
This code is never called for some reason and Windows handles any errors.
I set up the ThreadException in my _load event for the main form:
Application.ThreadException += MyExceptionHandler;
What would cause this behavior?
I tried to put it in the main loop but then the program becomes very unstable, crashing on other handlers.
Thanks
Mike
|
|
|
|
|
There is also an "UnhandledException" delegate in the Application class that you should assign your handler to.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Does anyone have any code for CRC8 calculation and polynomial calculation?
I'm trying to learn about this and having code to see it works would really help me.
Thank you.
|
|
|
|
|
CodeProject is your friend: "C# CCITT-8 CRC Algorithm:" [^].
There are three other articles on CRC8 on CodeProject: just search for them.
« There is only one difference between a madman and me. The madman thinks he is sane. I know I am mad. » Salvador Dali
|
|
|
|
|
|
If you found the CodeProject implementation, you can always ask questions on the article forum. That's what it's there for.
|
|
|
|
|
If someone could help me with this example [^] I would really appreciate that.
I'm not sure how to get it working, or why the author used "1, 2, 3" in the example. I would like to pass hex values.
|
|
|
|
|
turbosupramk3 wrote: I had some trouble with them and wanted to be able to ask questions so I posted here. Well, why aren't you asking specific questions based on the difficulties you are having with working with codes in the resources you found ?
We can't read your mind, and, in general, the more specific the question is, here, the more likely the poster is to get a satisfying answer, quickly.
Of course, if you are working with complex code you didn't write yourself, you may be getting error messages, or crashes, as you attempt to modify/use the code, and, possibly, only the author of the resource may be able to help you. In the case of CP articles/resources, as Pete points out, you can post a question to the author.
« There is only one difference between a madman and me. The madman thinks he is sane. I know I am mad. » Salvador Dali
|
|
|
|
|
Hi Bill. I would have asked specific questions in the first post had someone replied with a code example.
If you'll notice that after it was determined that no one had an example they wrote or used frequently, I started to ask specific questions about a link/piece of code I had found on the internet and was hoping to build from that.
|
|
|
|
|
hi
i will insert info person to database and i use janus control and bind all input from databinding and bind picturebox and mathimage that is editbox
and in run accure error:
Update requires a valid UpdateCommand when passed DataRow collection with modified rows
my code:
save:
try
{
bimehgozarBindingSource.EndEdit();
bimehgozarTableAdapter.Update(this.bimehDataSet.bimehgozar);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
new:
bimehgozarBindingSource.AddNew();
string query = "SELECT MAX(code_bg) FROM bimehgozar";
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=bimeh;Integrated Security=True");
SqlCommand comSelect = new SqlCommand(query, con);
con.Open();
string ID = comSelect.ExecuteScalar().ToString();
if (ID == "")
editBox8.Text = 1.ToString();
else
{
int a = Convert.ToInt32(ID);
a = a + 1;
editBox8.Text = a.ToString();
}
editBox1.Text = "";
editBox2.Text = "";
editBox3.Text = "";
editBox4.Text = "";
editBox5.Text = "";
editBox6.Text = "";
editBox7.Text = "";
editBox11.Text = "";
editBox12.Text = "";
editBox13.Text = "";
editBox14.Text = "";
pictureBox1.Image = null;
i am accure errore in save Button click
please help me i am tired. how save image when use janus control beacuse i use janus control not have value for insert.
wheather i need to convert image to array.
please guide me i want to insert info and long time accure error.
best regards
|
|
|
|
|
If you have a problem with Janus control, perhaps you need to contact the support forums for the people who wrote it. They will be the best placed to answer questions like this.
|
|
|
|
|
thanks i put my question in many forum of programing but i just now
my question in janus forum.
|
|
|
|
|
hello,
I developed a C # application I am connecting to the database , when I do a simple query the application launches and data are collected in the datagridview . but when I want to retrieve a lot of data and I run I click run the windows form does not appear and nothing appears .
Thank you
|
|
|
|
|
Well then ... don't do that! ("read a lot of data").
Use virtualization.
|
|
|
|
|
I have to retrieve a lot of data on my datagridview
|
|
|
|