|
Hi,
Jai, I have sending you the code from one of my application, please change it accordingly and let me know when done......
And it's only for jpg, and u cna do it for any one.....
protected void Button2_Click(object sender, EventArgs e)
{
string sSavePath;
string sThumbExtension;
int intThumbWidth;
int intThumbHeight;
sSavePath = _Default.fullpath;
sThumbExtension = "_thumb";
intThumbWidth = 160;
intThumbHeight = 120;
// If file field isn’t empty
if (FileUpload1.PostedFile != null)
{
// Check file size (mustn’t be 0)
HttpPostedFile myFile = FileUpload1.PostedFile;
int nFileLen = myFile.ContentLength;
if (nFileLen == 0)
{
lblOutput.Text = "No file was uploaded.";
return;
}
// Check file extension (must be JPG)
if (System.IO.Path.GetExtension(myFile.FileName).ToLower() != ".jpg")
{
lblOutput.Text = "The file must have an extension of JPG";
return;
}
// Read file into a data stream
byte[] myData = new Byte[nFileLen];
myFile.InputStream.Read(myData, 0, nFileLen);
// Make sure a duplicate file doesn’t exist. If it does, keep on appending an
// incremental numeric until it is unique
string sFilename = System.IO.Path.GetFileName(myFile.FileName);
int file_append = 0;
while (System.IO.File.Exists(( (sSavePath + sFilename))))
{
file_append++;
sFilename = System.IO.Path.GetFileNameWithoutExtension(myFile.FileName)
+ file_append.ToString() + ".jpg";
}
// Save the stream to disk
System.IO.FileStream newFile
= new System.IO.FileStream((sSavePath + sFilename),
System.IO.FileMode.Create);
newFile.Write(myData, 0, myData.Length);
newFile.Close();
// Check whether the file is really a JPEG by opening it
System.Drawing.Image.GetThumbnailImageAbort myCallBack =
new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
Bitmap myBitmap;
try
{
myBitmap = new Bitmap((sSavePath + sFilename));
// If jpg file is a jpeg, create a thumbnail filename that is unique.
file_append = 0;
string sThumbFile = System.IO.Path.GetFileNameWithoutExtension(myFile.FileName)
+ sThumbExtension + ".jpg";
while (System.IO.File.Exists((sSavePath + sThumbFile)))
{
file_append++;
sThumbFile = System.IO.Path.GetFileNameWithoutExtension(myFile.FileName) +
file_append.ToString() + sThumbExtension + ".jpg";
}
// Save thumbnail and output it onto the webpage
System.Drawing.Image myThumbnail
= myBitmap.GetThumbnailImage(intThumbWidth,
intThumbHeight, myCallBack, IntPtr.Zero);
// myThumbnail.Save((sSavePath + sThumbFile));
Image1.ImageUrl = @"~\" + (string)Session["user_name"].ToString() + @"\" + sSavePath + sFilename; //+ sThumbFile;
//Directory.GetCurrentDirectory() + @"\" + sThumbFile;
// Displaying success information
lblOutput.Text = "File uploaded successfully!";
TextBox3.Text = @"~\" + (string)Session["user_name"].ToString() + @"\" + sSavePath + sFilename;// sThumbFile;
// Destroy objects
myThumbnail.Dispose();
myBitmap.Dispose();
}
catch (ArgumentException errArgument)
{
// The file wasn't a valid jpg file
lblOutput.Text = "The file wasn't a valid jpg file.";
System.IO.File.Delete(sSavePath + sFilename);
}
}
}
public bool ThumbnailCallback()
{
return false;
}
|
|
|
|
|
hi Abhijit Jana,
please send me the html coding also
thanks
jai prakash
|
|
|
|
|
Html, Coding, is very big one becuase , Image uploading is a small part of the page, u can test it using Create a ImageBox, Take a fileupload control and 1 button
put the code in Button_1 Click
{
}
and in outsides....
ThumbnailCallback()
Any query ask me !!!!
|
|
|
|
|
hi Abhijit Jana,
what should i want to give in sThumbExtension = " ";
jai prakash
|
|
|
|
|
Hi jai,
jai aswitha wrote: sThumbExtension = " ";
I have mention sThumbExtension ="_thumbs"
u can give anything....
If you uplaod a file with abhijit.jpg
then its thumbs should be abhijit_thumbs.jpg
is it clear ??? or you want to ask some think different !!!!
|
|
|
|
|
i am also having pblm related to this .can i get this path pls.
|
|
|
|
|
Please check my reply to jai, for the same !!!
|
|
|
|
|
Why? Don't you have the ability to search the forum yourself?
Also, please don't use textspeak. It's really irritating.
Paul Marfleet
|
|
|
|
|
Hi All,
I want to display corresponding ImageButton of the different Products into GridView runtime.
I have maintained one field which holds ImagePath details(locally),but its not the permanent solution,(if the path changes).Reading Images and Storing Images in D/B is not required.
Any help is appreciated.
Hello There
|
|
|
|
|
Why you store imagePath in database?>just store Image name with extention like as image.jpg and give path in code.
for example
<img src='ImageForlder/<%# Eval("ImageName")%>' />
besT reGard
pAthAn
please don't forget to vote on the post that helped you.
|
|
|
|
|
Hi Imran,
First of all,thanks for the reply.My code or the business logic don't want to code the path,images will already be placed in a particular path and it should display retrieving path fom d/b.
One more thing,its actually Image Button.I hope it's clear now.
Regards,
Montu
Hello There
|
|
|
|
|
|
Hi all
I have a problem. Am tring to display data on dropdown list, i have two dropdown list. i'm displaying data on both from database. when the application starts running the first ddl will list out some data. when we select one the second ddl will display data according to that. but here the problem is, when i select one on first ddl, it is automaticaly errasing all the datas.....
i havint given any where clear command. y it ts not displaying. the problem i nly when it is connected to database. i tried a sample, it is working.
plz help me....
|
|
|
|
|
P_Elza wrote: i tried a sample, it is working.
Not sure what this means.
Have you set breakpoints to see what code is executed ? Best guess is that you're setting the data source on postback, which will clear all viewstate. But that doesn't seem to be exactly what you're describing, do you have a code sample ?
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillionOneHundredAndFortySevenMillionFourHundredAndEightyThreeThousandSixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it )
|
|
|
|
|
ya i have set
but its not entering to private void DdlCustomer_SelectedIndexChanged(object sender, System.EventArgs e) even if i change the selection.
Code Sample
<br />
private void Page_Load(object sender, System.EventArgs e)<br />
{<br />
if (!IsPostBack)<br />
{<br />
Production.Add_CustomerToCombo(DdlCustomer,DdlTitle,dgDetailData,SQL_SELECT_CUST_NAME);
}<br />
logintime.Text=System.DateTime.Now.ToLongDateString(); <br />
BtnSave.Visible=false;<br />
}<br />
<br />
<br />
private void DdlCustomer_SelectedIndexChanged(object sender, System.EventArgs e)<br />
{<br />
BtnSave.Visible=true;<br />
DdlTitle.Items.Clear();<br />
DdlTitle.Items.Add(new ListItem("---SELECT---","0"));<br />
<br />
}<br />
|
|
|
|
|
OK, then the combobox isn't set up to handle the event, or it's autopostback is not set to true. And, I still think your viewstate is probably off.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillionOneHundredAndFortySevenMillionFourHundredAndEightyThreeThousandSixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it )
|
|
|
|
|
autopostback is set to true and viewstate is on.
but i didnt get
Christian Graus wrote: combobox isn't set up to handle the event
|
|
|
|
|
Do one thing override the page init method put the code of populating the drop down in that method so it will populate every time regardless of postback
if you don't want to hit the database every time then put all values in session instead and and get vlaues from session or similar to like that
Thanks and Regards
Sandeep
If If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
|
|
|
|
|
Try to debug the application put a break point and see whats happening ?
i think after post back the drop down list is not getting populated
Thanks and Regards
Sandeep
If If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
|
|
|
|
|
Do you check IsPostBack when you load data collection for ddl? You should remember; page_load method works before every event-delegation method (ddl SelectedIndexChanged too).
we can work IT out! (Beatles)
|
|
|
|
|
hi..
i have a problem with following code in asp.net/vb.net
here i have a script to go one page to another in asp.net.
in my project i have 2 folders like lookups and PO.
now i want to go to Productformfactor page form PO Page
Productformfactor belongs to lookup folder and PO Page belongs to PO folder
if i don't use saperate folders then it is working...
i have used the following code in PO page to go productFormFactor
but iam getting error message.(i used this code in button click event)
CODE:
Page.ClientScript.RegisterStartupScript(Me.[GetType](), "openpopup", "window.open('Lookups/productFormFactor.aspx','test','scrollbars=2');")
thanku
siri.
siri
|
|
|
|
|
Why are you doing this ? Why not just add a button that calls the javascrpt directly without bothering with a postback ?
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillionOneHundredAndFortySevenMillionFourHundredAndEightyThreeThousandSixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it )
|
|
|
|
|
Good point.
---
"Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things."
-- Douglas Adams
|
|
|
|
|
thankyou Christian Graus
and the thing is if go to the Page2 from page1 then the values of controls should not be refresh and it shoul maintain it state.so, i used script.
and even i have tried with setting the enableviwesate=true...
but it is not working
can u plz help me
siri
|
|
|
|
|
I have no idea what your statement about pages means, how are the pages defined ?
It does not matter. You're writing code in a postback to inject javascript to run when the page reloads. Just putting the script directly into the html to run without a postback will do exactly the same thing.
None of the other stuff you're sayng makes any sense to me at all, perhaps you need to explain what you're trying to achieve, given that it seems likely that you're not tryng to do what it is that you're actually doing.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillionOneHundredAndFortySevenMillionFourHundredAndEightyThreeThousandSixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it )
|
|
|
|