Click here to Skip to main content
15,888,454 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: how to create crystal report into web page at runtime without mapping any columms at design template Pin
hiren dave26-Dec-08 19:01
hiren dave26-Dec-08 19:01 
QuestionHow to use Find Method for an Object Collection Pin
Kuricheti25-Dec-08 22:54
Kuricheti25-Dec-08 22:54 
AnswerRe: How to use Find Method for an Object Collection Pin
Brij25-Dec-08 23:44
mentorBrij25-Dec-08 23:44 
Questionhow to solve rendering problem of tab panel? Pin
mr_muskurahat25-Dec-08 22:31
mr_muskurahat25-Dec-08 22:31 
AnswerRe: how to solve rendering problem of tab panel? Pin
Abhijit Jana25-Dec-08 23:43
professionalAbhijit Jana25-Dec-08 23:43 
GeneralRe: how to solve rendering problem of tab panel? Pin
mr_muskurahat26-Dec-08 0:56
mr_muskurahat26-Dec-08 0:56 
AnswerRe: how to solve rendering problem of tab panel? Pin
Brij26-Dec-08 2:16
mentorBrij26-Dec-08 2:16 
QuestionUploading image from ContentPage of asp.net Pin
premprakashbhati25-Dec-08 21:42
premprakashbhati25-Dec-08 21:42 
hi,dear
iam working on uploading image from contentPage of asp.net ..its working fine when iam using a normal webpage...when iam giving in tag of normal webpage the code:
<form id="form1" enctype="multipart/form-data" runat="server">
</form>

its works fine i can upload my image ,but using ContentPage when iam not using this form tag here,but only at MasterPage..iam not getting image content in my Upload control..
>>>>iam using Controls in my ContentPage are:
1.input(file) HTML Control named filUpload
2.webButtonControl named btnUpload.

plz help me out...thanx in advance

Here is my MasterPage code part
<body>
    <form id="form1" enctype="multipart/form-data" runat="server">
    <asp:scriptmanager runat="server" id="scrpt1" xmlns:asp="#unknown" />
    <div>
 
</div></form></body>


ContentPage...Default3.aspx.cs

   protected override void Render(HtmlTextWriter writer)
    {

        base.Render(writer);
        this.Page.ClientScript.RegisterForEventValidation(btnUpload.ID);
    }
  

    protected  void btnUpload_Click(object sender, System.EventArgs e)
{
    
    // Initialize variables
    string sSavePath;
    string sThumbExtension;
    int intThumbWidth;
    int intThumbHeight;

    // Set constant values
    sSavePath = "images/";
    sThumbExtension = "_thumb";
    intThumbWidth = 160;
    intThumbHeight = 120;

    // If file field isn’t empty
    if (filUpload.PostedFile != null) ...//here iam getting the field empty...//
    {
        // Check file size (mustn’t be 0)
        HttpPostedFile myFile = filUpload.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(Server.MapPath(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(Server.MapPath(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(Server.MapPath(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(Server.MapPath(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 (Server.MapPath(sSavePath + sThumbFile));
            imgPicture.ImageUrl = sSavePath + sThumbFile;

            // Displaying success information
            lblOutput.Text = "File uploaded successfully!";

            // 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(Server.MapPath(sSavePath + sFilename));
        }
    }
}

public bool ThumbnailCallback()
{
    return false;
}        
    }

AnswerRe: Uploading image from ContentPage of asp.net Pin
Abhijit Jana25-Dec-08 21:58
professionalAbhijit Jana25-Dec-08 21:58 
GeneralRe: Uploading image from ContentPage of asp.net [modified] Pin
premprakashbhati25-Dec-08 23:23
premprakashbhati25-Dec-08 23:23 
GeneralRe: Uploading image from ContentPage of asp.net Pin
premprakashbhati26-Dec-08 3:05
premprakashbhati26-Dec-08 3:05 
AnswerRe: Uploading image from ContentPage of asp.net Pin
dkkeyan25-Dec-08 23:27
dkkeyan25-Dec-08 23:27 
QuestionASP.NET GridView Pin
Socheat.Net25-Dec-08 20:56
Socheat.Net25-Dec-08 20:56 
AnswerRe: ASP.NET GridView Pin
Abhijit Jana25-Dec-08 21:34
professionalAbhijit Jana25-Dec-08 21:34 
GeneralRe: ASP.NET GridView Pin
Socheat.Net25-Dec-08 22:37
Socheat.Net25-Dec-08 22:37 
GeneralRe: ASP.NET GridView Pin
Brij25-Dec-08 22:43
mentorBrij25-Dec-08 22:43 
AnswerRe: ASP.NET GridView Pin
Brij25-Dec-08 22:23
mentorBrij25-Dec-08 22:23 
QuestionChatting Pin
smraj150325-Dec-08 20:40
smraj150325-Dec-08 20:40 
AnswerRe: Chatting Pin
Abhijit Jana25-Dec-08 21:01
professionalAbhijit Jana25-Dec-08 21:01 
Questionconverting asp.net code from 2003 - 2005 problem.... Pin
MS Lee25-Dec-08 20:35
MS Lee25-Dec-08 20:35 
AnswerRe: converting asp.net code from 2003 - 2005 problem.... Pin
Abhijit Jana25-Dec-08 21:03
professionalAbhijit Jana25-Dec-08 21:03 
GeneralRe: converting asp.net code from 2003 - 2005 problem.... Pin
MS Lee25-Dec-08 21:53
MS Lee25-Dec-08 21:53 
GeneralRe: converting asp.net code from 2003 - 2005 problem.... Pin
Abhijit Jana25-Dec-08 22:06
professionalAbhijit Jana25-Dec-08 22:06 
GeneralRe: converting asp.net code from 2003 - 2005 problem.... Pin
MS Lee25-Dec-08 23:03
MS Lee25-Dec-08 23:03 
GeneralRe: converting asp.net code from 2003 - 2005 problem.... Pin
Abhijit Jana25-Dec-08 23:41
professionalAbhijit Jana25-Dec-08 23:41 

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.