Click here to Skip to main content
16,005,141 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: Problem with gridview's datasource Pin
Christian Graus23-Oct-07 23:24
protectorChristian Graus23-Oct-07 23:24 
GeneralRe: Problem with gridview's datasource Pin
Zoltan Aszalos23-Oct-07 23:38
Zoltan Aszalos23-Oct-07 23:38 
QuestionThe aspx page should not refresh when it is loaded on linkbutton click Pin
kishoregani23-Oct-07 22:00
kishoregani23-Oct-07 22:00 
QuestionUploaded image into thumbnail Pin
jai 12323-Oct-07 21:37
jai 12323-Oct-07 21:37 
AnswerRe: Uploaded image into thumbnail Pin
pmarfleet23-Oct-07 21:54
pmarfleet23-Oct-07 21:54 
GeneralRe: Uploaded image into thumbnail Pin
jai 12323-Oct-07 22:16
jai 12323-Oct-07 22:16 
GeneralRe: Uploaded image into thumbnail Pin
pmarfleet23-Oct-07 22:31
pmarfleet23-Oct-07 22:31 
GeneralRe: Uploaded image into thumbnail Pin
Abhijit Jana23-Oct-07 22:35
professionalAbhijit Jana23-Oct-07 22:35 
Hi,
Jai, I have sending you the code from one of my application, please change it accordingly and let me know when done...... Smile | :)

And it's only for jpg, and u cna do it for any one..... Smile | :) Smile | :) Smile | :)
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;
}


Best Regards
-----------------
Abhijit Jana
View My CodeProject Articles

"Success is Journey it's not a destination"

GeneralRe: Uploaded image into thumbnail Pin
jai 12323-Oct-07 22:55
jai 12323-Oct-07 22:55 
GeneralRe: Uploaded image into thumbnail Pin
Abhijit Jana23-Oct-07 23:02
professionalAbhijit Jana23-Oct-07 23:02 
GeneralRe: Uploaded image into thumbnail Pin
jai 12324-Oct-07 1:46
jai 12324-Oct-07 1:46 
GeneralRe: Uploaded image into thumbnail Pin
Abhijit Jana24-Oct-07 2:55
professionalAbhijit Jana24-Oct-07 2:55 
GeneralRe: Uploaded image into thumbnail Pin
Padma N24-Oct-07 21:08
Padma N24-Oct-07 21:08 
GeneralRe: Uploaded image into thumbnail Pin
Abhijit Jana24-Oct-07 22:46
professionalAbhijit Jana24-Oct-07 22:46 
GeneralRe: Uploaded image into thumbnail Pin
pmarfleet25-Oct-07 7:10
pmarfleet25-Oct-07 7:10 
QuestionDisplay Image in GridView Pin
Montu7623-Oct-07 21:31
Montu7623-Oct-07 21:31 
AnswerRe: Display Image in GridView Pin
Imran Khan Pathan23-Oct-07 22:45
Imran Khan Pathan23-Oct-07 22:45 
GeneralRe: Display Image in GridView Pin
Montu7624-Oct-07 5:21
Montu7624-Oct-07 5:21 
AnswerRe: Display Image in GridView Pin
Abhijit Jana23-Oct-07 23:06
professionalAbhijit Jana23-Oct-07 23:06 
QuestionPlz help me to display data on Dropdownlist Pin
P_Elza23-Oct-07 21:13
P_Elza23-Oct-07 21:13 
AnswerRe: Plz help me to display data on Dropdownlist Pin
Christian Graus23-Oct-07 21:19
protectorChristian Graus23-Oct-07 21:19 
GeneralRe: Plz help me to display data on Dropdownlist Pin
P_Elza23-Oct-07 21:41
P_Elza23-Oct-07 21:41 
GeneralRe: Plz help me to display data on Dropdownlist Pin
Christian Graus23-Oct-07 22:49
protectorChristian Graus23-Oct-07 22:49 
GeneralRe: Plz help me to display data on Dropdownlist Pin
P_Elza23-Oct-07 23:41
P_Elza23-Oct-07 23:41 
GeneralRe: Plz help me to display data on Dropdownlist Pin
Sandeep Akhare24-Oct-07 1:48
Sandeep Akhare24-Oct-07 1:48 

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.