Wrox Programmer Forums
|
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 26th, 2005, 08:42 PM
Registered User
 
Join Date: Apr 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to leeyoung
Default Upload Images Help

Now I have a question:
TestUploadImage.aspx
<%@ Page language="c#" Codebehind="TestUploadImage.aspx.cs" AutoEventWireup="false" Inherits="OVOP.Admin.TestUploadImage" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
     <HEAD>
          <title>TestUploadImage</title>
          <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
          <meta name="CODE_LANGUAGE" Content="C#">
          <meta name="vs_defaultClientScript" content="JavaScript">
          <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
          <script language="Javascript">
          function GetImage(CtrlName)
          {

          /************************************************** ** Use Javascript method (window.open) to PopUp a new window which contain a Calendar Control. In the meantime, we'll pass the Parent Form Name and Request Control Name in the QueryString! ************************************************** ***/
          ChildWindow = window.open('UploadImages.aspx?FormName=' + document.forms[0].name + '&CtrlName=' + CtrlName, "UploadImage", "width=350,height=300,top=200,left=200,toolbars=no ,scrollbars=no,status=no,resizable=no"); } function CheckWindow() { ChildWindow.close(); }

                    </script>
     </HEAD>
     <body MS_POSITIONING="GridLayout">
          <form id="Form1" method="post" runat="server">
               <asp:textbox id="txtImage" runat="server" Width="200px"></asp:textbox><A href="javascript:GetImage('txtImage')"><IMG alt="Image Upload" src="SmallCalendar.gif" border="0"></A>
          </form>
     </body>
</HTML>

UploadImages.aspx
using System;
using System.Configuration;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.IO;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace OVOP.Admin
{
     /// <summary>
     /// Summary description for UploadImages.
     /// </summary>
     public class UploadImages : System.Web.UI.Page
     {
          protected System.Web.UI.HtmlControls.HtmlInputButton btnCloseWindow;
          protected System.Web.UI.HtmlControls.HtmlInputButton btnUploadFile;
          protected System.Web.UI.HtmlControls.HtmlInputFile UploadFile;
          public string uploadFolder="D:\\Multi Ltd Projects\\OVOP\\ProductImages\\";
          public string strFormName;
          public string strCtrlName;
          protected System.Web.UI.WebControls.Button Button1;
          public string strSelectedImage;

          private void Page_Load(object sender, System.EventArgs e)
          {


          if (!IsPostBack)
               {

                    if (UploadFile.PostedFile != null)
                    {
                         try
                         {
                              // Put user code to initialize the page here
                              string sPath=uploadFolder;
                              //Split the client side path (C:\Picture Images\images.jpg) by taken '\' as a delimiter.
                              //Take the last index of the array return by splitting.
                                   string clientsideFilePath = UploadFile.PostedFile.FileName;
               char[] delimeter = "\\".ToCharArray();
               string[] strList = clientsideFilePath.Split(delimeter, 100);
               string fileNameOnly = strList[strList.Length-1];
                                                       Stream imgStream = UploadFile.PostedFile.InputStream;
                              int imgLen = UploadFile.PostedFile.ContentLength;
                              //UploadFile.PostedFile.SaveAs("C:\\Temp\\"+UploadFi le.Value);
                              string imgContentType = UploadFile.PostedFile.ContentType;
                              //strSelectedImage = fileNameOnly;
                              //txtImgName.Value = fileNameOnly;
                              byte[] imgBinaryData = new byte[imgLen];
                              int n = imgStream.Read(imgBinaryData,0,imgLen);
                              strSelectedImage = fileNameOnly;
                              UploadFile.PostedFile.SaveAs(sPath + fileNameOnly);
                              Response.Write("Insert Sucessfully");
                         }
                         catch(Exception exc)
                         {
                              Response.Write("Exception in Main: " + exc.ToString());

                         }
                    }
               }
               strFormName = Request.QueryString["FormName"];
               strCtrlName = Request.QueryString["CtrlName"];
               //strSelectedImage = fileNameOnly;

                         //strSelectedImage=UploadFile.PostedFile.FileName;
          // strSelectedImage = fileNameOnly;

          }

          #region Web Form Designer generated code
          override protected void OnInit(EventArgs e)
          {
               //
               // CODEGEN: This call is required by the ASP.NET Web Form Designer.
               //
               InitializeComponent();
               base.OnInit(e);
          }

          /// <summary>
          /// Required method for Designer support - do not modify
          /// the contents of this method with the code editor.
          /// </summary>
          private void InitializeComponent()
          {
               this.Button1.Click += new System.EventHandler(this.Button1_Click);
               this.Load += new System.EventHandler(this.Page_Load);

          }
          #endregion

          private void Button1_Click(object sender, System.EventArgs e)
          {


               if (UploadFile.PostedFile != null)
               {
                    try
                    {
                         // Put user code to initialize the page here
                         string sPath=uploadFolder;
                         //Split the client side path (C:\Picture Images\images.jpg) by taken '\' as a delimiter.
                         //Take the last index of the array return by splitting.
                         string clientsideFilePath = UploadFile.PostedFile.FileName;
                         char[] delimeter = "\\".ToCharArray();
                         string[] strList = clientsideFilePath.Split(delimeter, 100);
                         string fileNameOnly = strList[strList.Length-1];
                         Stream imgStream = UploadFile.PostedFile.InputStream;
                         int imgLen = UploadFile.PostedFile.ContentLength;
                         //UploadFile.PostedFile.SaveAs("C:\\Temp\\"+UploadFi le.Value);
                         string imgContentType = UploadFile.PostedFile.ContentType;
                         //strSelectedImage = fileNameOnly;
                         //txtImgName.Value = fileNameOnly;
                         byte[] imgBinaryData = new byte[imgLen];
                         int n = imgStream.Read(imgBinaryData,0,imgLen);

                         UploadFile.PostedFile.SaveAs(sPath + fileNameOnly);
                         strSelectedImage = fileNameOnly;
                         Response.Write(fileNameOnly);

                         Response.Write("Insert Sucessfully");
                    }
                    catch(Exception exc)
                    {
                         Response.Write("Exception in Main: " + exc.ToString());

                    }
               }
          }


     }
}
when I select a image name it doesn't effect into textbox, that means when I press select file button it will get the image file name into textbox
Thanks

Lee





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to upload images? vipin k varghese Beginning PHP 1 June 3rd, 2008 03:59 AM
Problem with images upload M.Poalim Beginning PHP 1 May 11th, 2007 07:25 PM
Cannot upload a whole images vnguyen Java Databases 1 July 25th, 2005 03:46 PM
upload images mccoco Classic ASP Professional 2 September 23rd, 2003 04:30 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.