|
are they in the same method ?
|
|
|
|
|
Yes and I'm sure it was working yesterday although I have extended my code a bit
|
|
|
|
|
can you please give the exact code(do a copy paste)?
EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.
|
|
|
|
|
I am using populating a ListBox with the files I want to resize and when the user clicks a button, the method goProcessImages is called and I traverse through each one resizing it (well I'm trying to!). Thanks - here is my code behind (sorry it's a bit of a mess but I've been commenting out things to find out what's going wrong):
using System;
using System.Collections;
using System.Configuration;
using System.Drawing;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;
public partial class ResizeImage : System.Web.UI.Page
{
ArrayList imageNames = new ArrayList();
string imagesDir = "D:\\Website\\BookImages\\";
//get path of Books dir in website
protected void Page_Load(object sender, EventArgs e)
{
string imgForLB = "";
if (!IsPostBack)
{
int i = 0;
try
{
foreach (string img in Directory.GetFiles(imagesDir, "*.jpg"))
{
imageNames.Add(img.Remove(0, 22));
}
foreach (string img in Directory.GetFiles(imagesDir, "*.jpeg"))
{
imageNames.Add(img.Remove(0, 22));
}
foreach (string img in Directory.GetFiles(imagesDir, "*.gif"))
{
imageNames.Add(img.Remove(0, 22));
}
}
catch
{
Response.Write("We are currently experiencing problems in obtaining images from the directory " +
imagesDir + "Make sure you are offline and this directory exists on your laptop and it is not empty.");
}
//write out image names to screen for Angell to check
for (i = 0; i < imageNames.Count; i++)
lbFileNames.Items.Add(imageNames[i].ToString());
}
}
// Required by GetThumbnailImage() method, but not used
public bool ThumbnailCallback()
{
return true;
}
protected void goProcessImages(object sender, EventArgs e)
{
string imageName = "";
//resize each file listed in listbox
foreach (ListItem item in lbFileNames.Items)
{
imageName = item.ToString();
if (imageName != "")
{
//createThumbnail(imageName, 400);
createThumbnail(imageName, 100);
}
}
}
protected void createThumbnail(string imgName, int newHeight)
{
string pathToFile = Server.MapPath("Images/Books/");
int origHeight = 0;
int origWidth = 0;
string thumbImgName = "";
string existsFilePath = "";
bool imageExists = false;
//get path of Books dir in website
string imgFullPath = "";
string fullPath = "";
//Once we have an instance of the Image class we can determine the height and width
//of the image by checking the Height and Width properties.
if (newHeight == 100)
thumbImgName = imgName.Replace(".", "-s.");
else
thumbImgName = imgName;
//path of image to retrieve (before resizing)
imgFullPath = imagesDir + imgName;
Response.Write("full path of image is " + imgFullPath);
//path of image to save (after resizing)
fullPath = pathToFile + thumbImgName;
//imgFullPath = imagesDir + imgName;
//try
//{
// create an image object, using the filename we just retrieved
System.Drawing.Image fullSizeImg = System.Drawing.Image.FromFile(imgFullPath);
//}
//catch
//{
//Response.Write("We are experiencing problems with the server at the moment.<br />" +
//"Please try again later.");
//}
//get orig height
origHeight = fullSizeImg.Height;
//get orig width
origWidth = fullSizeImg.Width;
float newWidthFloat = ((float)newHeight / (float)origHeight) * (float)origWidth;
int newWidth = Convert.ToInt32(newWidthFloat);
//check in case there is already an image with this name in website
existsFilePath = pathToFile + thumbImgName;
Response.Write(existsFilePath);
if (File.Exists(existsFilePath))
{
imageExists = true;
//need confirmation message
}
//if image height > the new target height, resize
//if (origHeight > newHeight)
//{
try
{
// create the actual thumbnail image
System.Drawing.Image thumbNailImg = fullSizeImg.GetThumbnailImage(newWidth, newHeight, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
}
catch
{
if (newHeight == 100)
{
Response.Write("We are experiencing problems with the server at the moment.<br />A thumbnail version of " + imgName + " has not been created. Please try again later.");
}
else
{
Response.Write("We are experiencing problems with the server at the moment.<br />" + imgName + " has not been resized. Please try again later.");
}
}
//try
//{
//save to website Books dir
//if (thumbNailImg != null)
thumbNailImg.Save(fullPath);
//}
//catch
//{
// Response.Write("We are experiencing problems with the server at the moment.<br />" + thumbImgName + " has not been saved to the website. Please try again later.");
//}
//Clean up / Dispose...
//thumbNailImg.Dispose();
//}
//else
//{
//try
//{
//save original image to website Books dir
//fullSizeImg.Save(fullPath);
//}
//catch
//{
//Response.Write("We are experiencing problems with the server at the moment.<br />" + thumbImgName + " has not been saved to the website. Please try again later.");
//}
//Clean up / Dispose...
//fullSizeImg.Dispose();
//}
}
}
|
|
|
|
|
Member 3402886 wrote: try
{
// create the actual thumbnail image
System.Drawing.Image thumbNailImg = fullSizeImg.GetThumbnailImage(newWidth, newHeight, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
}
Because of you are creating the variable inside try block, it is showing the error.
should be like this
System.Drawing.Image thumbNailImg;
try
{
thumbNailImg = fullSizeImg.GetThumbnailImage(newWidth, newHeight, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
}
EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.
|
|
|
|
|
Thanks - tried that but get message:
CS0165: Use of unassigned local variable 'thumbNailImg'
on line:
thumbNailImg.Save(fullPath);
Thanks
Lorna
|
|
|
|
|
I dont think so,
Because GetThumbnailImage returns an Image object and thumbNailImg is also an Image object.
Am I right?
EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.
|
|
|
|
|
Member 3402886 wrote: CS0103: The name 'thumbNailImg' does not exist in the current context
Show your full code.
Member 3402886 wrote: fullSizeImg.GetThumbnailImage
Resizing image using GetThumbnailImage is inefficient and it returns only the thumbnail image attached to each image. So you will get pretty poorly resized image.
Create a Bitmap with the new size and width, load your image into a Graphics instance, use DrawImage() to draw image into the required size. Save the bitmap. You will get image resized without loosing quality.
|
|
|
|
|
HI
guys i am facing problem, in my application i am using data type decimal, when i get the value from data base and show in text box if the value is e.g. 99 it shows 99.00000 as i have specified 5 after precision in sql server, how can i convert the 99.00000 to 99 can any one let me know about it thankx in advance.
|
|
|
|
|
Convert.ToInt32(DecimalValue)
or
lblValue.Text = decimalValue.ToString("#,#0");
or
txtValueBox.Text = decimalValue.ToString("#,#0");
|
|
|
|
|
thansk for your answer but in case if there is 99.45 in database it converts it back to 99
in this case i want to show 99.4, kindly reply ASAP.
|
|
|
|
|
thanks for your answer but in case if there is 99.45 in database it converts it back to 99
in this case i want to show 99.45, kindly reply ASAP.
|
|
|
|
|
|
thanks i have did it, thanks for ur help.
|
|
|
|
|
i want today present time
for that i used this code
Public Function Date6() As String
Dim NewTime As DateTime
NewTime = Now()
Return NewTime.ToShortTimeString()
End Function
its working in local host i.e when run project
but the same page when i upload into site
it is not giving correct time
plz help me
thanks in advance
vijay
|
|
|
|
|
that usuaully means your server is displaying the wrong time, check this out first
|
|
|
|
|
Hi
I am wanting to create a form that someone can send an email to a list of people being pulled out of my database, but struggling to work out how i can bring all the email addresses back? Is there a way that i can bring all of them back into a label/textbox and seperate them with a ; and use that for my To? Or would it be best to loop through the records?
Any help would be appreciated.
Regards
Adam
|
|
|
|
|
something like:
"select email from table"
store results in a datatable
for each row in database add result to your label or To textbox and use += for each row.
that is a start anyway
|
|
|
|
|
This will give you a list of comma delimited email addresses (eg bob@a.co.uk, fred@abc.com, joe@khg.com)
DECLARE @EmailList varchar(1000)
SELECT @EmailList = COALESCE(@EmailList + ', ', '') + e.EmailAddress
FROM emailtable
WHERE .....
SELECT @EmailList
Of course you may want to change froma comma to a semi-colon
Hopefully this will help
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Hi
Thanks for your reply, unfortunatley not, ive not worked with COALESCE before and im not sure how you mean to go about putting this in my sqldatasource? The table is just made of 2 columns.
membersemail
id - int
email - varchar
Thanks
Adam
|
|
|
|
|
COALESCE simply takes the first nonnull value from the list given. You would do it as a bit of SQL, running on a connection/sql command, not a datasource, it just returns a single column.
Hopefully this clarifies things
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Hi!
I have a site using MySQL provider for users and membership and their password are hashed.
Now I am rewriting the code and moving to MSSQL provider where the users password are stored hashed but also uses "salt" which I haven't heard of before but seems like som kind of random number to generate the hashed password I guess.
Now to my question, can I transfer all my users to the new database and let them keep the same password without bothering them or do I have to give them/ask them for a new password at the same time as they move to the new site? My membership database in MySQL don't have any column for "salt". Only the hashed password. Is there any way to copy their old hashed password to the new format that MSSQL provider wants?
|
|
|
|
|
How to write Validation code for Textbox control in .Js file.
I am using masterPages, and the textbox control is in default.aspx.
Now my aim is to write required field validation(CleintSide validation) for that textbox in validation.Js file.
How to call textbox control with name txtname in validation.Js to check is it empty or not.
When i Write in the pagebehind, i write like this
<script type="text/javascript" language="javascript">
function validate()
{
var=document.getElementId("<%= txtname.CleintID %>");
if(var=="")
alert("");
return false;
}
</script>
when i write like above code in validation.Js file it is not working.
Please provide solution for that...
Thanks
Pinna
|
|
|
|
|
What you can do here is to write a function in your validation file which will accept the textbox control as parameter and will return true/false depending upon the criteria.
This method you can call in the web page where your control is available.
Apurva Kaushal
|
|
|
|
|
I want to add an event to a text, just as we have hyperlinks, so that when the user clicks on that text, i want to perform some action in the code-behind.
I want something similar to what is available here in this forum,
u click the 'subject' text of this message, & you can read it ...
|
|
|
|