Пример #1
0
    protected void NextButton2_Click(object sender, EventArgs e)
    {
        // Needs a file
        if (!UploadImageControl.HasFile)
        {
            StaticMethods.UpdateStatus("Please upload a file.", false, statusLabel);
            return;
        }

        // Needs the correct file type
        if (UploadImageControl.PostedFile.ContentType != "image/jpeg")
        {
            StaticMethods.UpdateStatus("File type of uploaded file is incorrect.", false, statusLabel);
            return;
        }

        Directory.CreateDirectory(MapPath("/Uploads/" + Session["UserID"]));

        string destDir  = MapPath("/Uploads/" + Session["UserID"]);
        string savePath = destDir + @"\" + UploadImageControl.FileName;

        try
        {
            UploadImageControl.SaveAs(savePath);
        }
        catch (Exception ex)
        {
            StaticMethods.UpdateStatus("Failed to upload : " + savePath + " : " + ex.ToString(), false, statusLabel);
            return;
        }

        StaticMethods.UpdateStatus("Thanks " + Session["UserID"] + " - Successfully uploaded (" + new FileInfo(savePath).Name + ") to : " + @"\Uploads\" + Session["UserID"], true, statusLabel);
        LastFileUploaded.Value = new FileInfo(savePath).Name;
        MultiViewControl.ActiveViewIndex++;
    }