|
Hi,
I am trying to upload an image and resize it. the image being uploaded will be saved in photos and thumbs directory. I have given network service and iusr_machinename write access to both folders. the upload works fine in local machine its just when i try to upload via a remote server i get error "A generic error occurred in GDI+."
below are my codes for upload click event. please help
try
{
String file = "";
String thumb = "";
if (flUpload.PostedFile.ContentLength > 0)
{
file = flUpload.FileName;
thumb = "";
String[] strNew = file.Split('.');
strNew[0] = DateTime.Now.Ticks.ToString();
file = strNew[0] + "." + strNew[1];
thumb = strNew[0] + "_t." + strNew[1];
ImageName = file;
ImagePath = Server.MapPath("~/photos") +"\\"+ ImageName;
Response.Write(ImagePath);
ImageThumbName = thumb;
ImageThumbPath = Server.MapPath("~/thumbs") + "\\" + ImageThumbName;
Response.Write(ImageThumbPath);
using (System.Drawing.Image Img = new Bitmap(flUpload.FileContent))
{
Size ThumbNailSize = NewImageSize(Img.Height, Img.Width, 100);
Size ImageSize = NewImageSize(Img.Height, Img.Width, 500);
using (System.Drawing.Image ImgThnail = new Bitmap(Img, ThumbNailSize.Width, ThumbNailSize.Height))
{
ImgThnail.Save(ImageThumbPath, Img.RawFormat);
ImgThnail.Dispose();
}
using (System.Drawing.Image Img1 = new Bitmap(Img, ImageSize.Width, ImageSize.Height))
{
Img1.Save(ImagePath, Img.RawFormat);
Img1.Dispose();
}
Img.Dispose();
}
}
public Size NewImageSize(int OriginalHeight, int OriginalWidth, double FormatSize)
{
Size NewSize; double tempval;
if (OriginalHeight > FormatSize && OriginalWidth > FormatSize)
{
if (OriginalHeight > OriginalWidth)
tempval = FormatSize / Convert.ToDouble(OriginalHeight);
else
tempval = FormatSize / Convert.ToDouble(OriginalWidth);
NewSize = new Size(Convert.ToInt32(tempval * OriginalWidth), Convert.ToInt32(tempval * OriginalHeight));
}
else
NewSize = new Size(OriginalWidth, OriginalHeight); return NewSize;
}
|
|
|
|
|
Check if you have access rights to save to the shared / network folder.
There are only 10 types of people in this world — those who understand binary, and those who don't. |
|
|
|
|
|
what do you mean. not sure how i do that as the website is hosted remotely and its with the hosting provider.
|
|
|
|
|
|
Happy new year...
I have a list of objects I would like to use to populate a datagridview. I would somehow like to have each row bound to a specific object.
I can see how that object class can be added as a datasource, but I'm not sure how to get the objects from my list added as a row.
Anyone care to help? Also, is this the right direction?
Thanks for your time.
|
|
|
|
|
Message Closed
modified 23-Nov-14 7:14am.
|
|
|
|
|
Before the grid is populated, there are no rows to enumerate in the grid.
If the class is used as a datasource, adding rows 'dgView.Rows.Add()' creates an exception stating 'Rows cannot be programmatically added to the DataGridView's row collection'
I'm using the class as the view bindng source. If this is correct, how do I get the list of obects into the grid?
If there is a different approach that would be better than what I'm attempting, please comment.
Thank you for your time.
modified on Sunday, January 3, 2010 12:04 PM
|
|
|
|
|
You can retrieve the object via DataBoundItem property.
|
|
|
|
|
Hi frnds ... I was trying to connect a database which has an extension of .mdf .... but in the crystal report this extension is not filtered ... I want to know how to connect this .mdf file ... Please help
Thank you
|
|
|
|
|
i need some guidance regarding c# winsock programming, im a beginner in programming and network applications. i understand the client/server idea.
server -> socket() bind() listen() accept() {send() recv()} close()
client -> socket() connect() {send() recv()} close()
--
i also know Socket.Connected Property to test if connected.
--
where i am having difficulty is in both server and client how to implement send() and recv() [events]. i know how to send and receive but to do it while keeping the connection seems to very vague in google links.
most examples on google just creat the connection and may send some data or receive some data and the connection is closed.
the while(true) on server runs in a loop and accepts new connections.
i need to know how to implement send and recv (events) so the connected clients and server can keep on exchanging data using the same connection.
lots of the web examples have the server running in a loop and the client makes a new connection whenever data needs to be sent, it doesn't seem efficient to me.
i have also seen server loop running on its own thread to avoid gui lockups but there also the actual communication seems vague.
so. i would like info on how to handle send and recv in a structured manner.
thanks for reading and a very happy new year to you.
---------------------
my current approach is wrong, it concerns blocking.. i should be using .NET asynchronous socket programming.
thanks.
modified on Saturday, January 2, 2010 1:36 PM
|
|
|
|
|
You need another thread which accepts messages from clients and process it. Take a look at this[^] MSDN page.
New year wishes to you too.
Best wishes,
Navaneeth
|
|
|
|
|
.NET makes this stuff pretty straight forward.
Server side, use a TcpListener to accept incoming connections from the client. Once accepted, which gives you a TcpClient, the ususal practice is to create a new thread and pass it the TcpClient and let it do its server side stuff. If the connection is likely to be brief, use the ThreadPool.
On the client, just use a TcpClient to connect to the server.
Generally, the connection stays open until either end closes it, or it *may* get closed due to inactivity timeouts - not sure.
You can attach a NetworkStream to the TcpClient at both ends, so you just end up with a duplex stream you can read and write to.
Cassini is a little web server from the early days of .NET which allowed people to develop ASP.NET applications. Have a look at the source of that for some patterns. http://blogs.msdn.com/dmitryr/archive/2005/09/27/474534.aspx[^]
Regards,
Rob Philpott.
|
|
|
|
|
Hi all...
At runing the following function i get the exeption "Arithmetic operation resulted in an overflow", an exeption arises from the underlining line of code :
public static int OnesSum(byte[] bytes, int start, int len)
{
MemoryStream memStream = new MemoryStream(bytes, start, len);
BinaryReader br = new BinaryReader(memStream);
Int32 sum = 0;
UInt16 val;
while (memStream.Position < memStream.Length -1)
{
val = (UInt16)IPAddress.NetworkToHostOrde(br.ReadInt16());
sum += val;
}
// if we have a remaining byte we should add it
if (memStream.Position < len)
{
sum += br.ReadByte();
}
// fold the sum into 16 bits
while((sum >> 16) != 0)
{
sum = (sum & 0xffff) + (sum >> 16);
}
return sum;
}
|
|
|
|
|
Have you tried making val an Int32 (and performing the appropriate cast when that method returns it?
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Hi,
The problem here is the cast to UInt16 which fails when the IPAddress byte order reversal method returns a negative value. Overflow checking must be disabled to allow the 16 bit result which is typed as Int16 to be successfully assigned to an unsigned type. Use the unchecked keyword to do this.
val = unchecked((UInt16)IPAddress.NetworkToHostOrder(br.ReadInt16()));
Alan.
|
|
|
|
|
Alan N wrote: val = unchecked((UInt16)IPAddress.NetworkToHostOrder(br.ReadInt16()));
That will always return 0.
The unchecked (UInt16) cast throws away the higher-order bits - but NetworkToHostOrder just swapped the byte order, so ALL the input bits will be thrown away.
I'm not sure what he wanted to do in the first place.
|
|
|
|
|
Not really, the overload with a short as input also has a short as result, so he's really just casting a short to an ushort
|
|
|
|
|
Oh, I didn't know there were multiple overloads. I thought it was for 32-bits only (as that's the size of an IPAddress), casting from int to ushort.
|
|
|
|
|
In that case you would have been right, of course
I suppose this overload can be useful for port numbers, I'm not sure why there is an overload for longs as well though..
|
|
|
|
|
I have written a User Control and made it dll from a classLibrary Project.
This User Control get the Name of the Form (in Project that we use this dll) in textbox1 and then do something with the controls on this form. Now my question is how i can Cast textbox1.Text (of this user control) to Form ?
|
|
|
|
|
Well, for one thing, you could pass in the form object into the user control itself.
There are only 10 types of people in this world — those who understand binary, and those who don't. |
|
|
|
|
|
This is rarely a good idea. If the user control needs acces to a Form object, it should have a Form property OR extend the Form class.
Also when the user control is dropped onto a form (or other container) in the designer, a parameterless constructor is used/needed.
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
You can use the Parent property to access the container the user control is in - this may or may not be a form... it could be a groupbox, a panel etc, you can check by using is or as . If it's not a form, check the parent's parent etc etc...
This is normally the wrong way round of doing things though as you will effectively be coupling your user control to a form and if you want to manipulate other controls on the form then you will be coupling to those too. If your control is then used in a different container and/or the expected controls aren't present you will end up with problems. A better solution is to expose events, properties and methods in your user control that it's host form can access, then the host form can control all it's controls including your user control.
If you are wanting a 'controller' form with your user control acting as the controller - you would be better to create a custom form for this purpose rather than a user control IMO.
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
see i use this user control in FormA and when the project runs it gets any form name execpt itself(the form that has this user control) in textbox1 (this textbox1 is also in the user control)and then the user control brings out all control on that form and show all properties of that control.
I have used this code in User Control:
Type type = Type.GetType(txtFormName.Text, false, true);
Form frm = Activator.CreateInstance(type) as Form;
I get this error :
Value cannot be null.
Parameter name: type.
Alert :
This user control has been made in another project and i have build DLL and now I use this DLL in my another projects.
|
|
|
|
|
Very good day all,
Is there a built in control & classes in C# allow me to draw a circle "dynamically"?
like the image in this link?
thank you!
|
|
|
|