<%@ Page Language="c#" Debug="true" Trace="true"%>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<html>
<script runat =server>
      void UploadBtn_Click(Object sender, EventArgs e) {
         String filename;
         String filename1;
         String[] filename2;
         int q;
         filename=UploadFile.PostedFile.FileName ;
         filename2=filename.Split(new Char[] {'\\'});
         q=filename2.GetUpperBound(0);
         filename1=filename2[q];
         dis.Text="上传文件名:"+filename1+"<br/>";
         UploadFile.PostedFile.SaveAs(Server.MapPath(filename1));
         ImageEditor.Visible = true;
         dis.Text+="文件大小:"+UploadFile.PostedFile.ContentLength+"字节数";
         Image1.Src=filename1;      
      } 
      void UpdateBtn_Click(Object sender, EventArgs e) {
        String filename1;
   filename1=Image1.Src;
   System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(filename1));
   System.Drawing.Image newimage = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppRgb);
   Graphics g = Graphics.FromImage(newimage);
   g.DrawImage(image,0,0,image.Width,image.Height);
   Font f = new Font(FontType.SelectedItem.Text, Int32.Parse(FontSize.SelectedItem.Text));
   Brush b = new SolidBrush(Color.Red);
   g.DrawString(Caption.Text, f, b, 10, 140);
   g.Dispose();
   //System.Drawing.Image thumbImage = newimage.GetThumbnailImage(Convert.ToInt32(Width.Text),Convert.ToInt32(Height.Text),null,0);
   image.Dispose();
  // thumbImage.Save(Server.MapPath(filename1), ImageFormat.Jpeg);
   Image1.Src=filename1;       
   Caption.Text="";     
      }   </script>

解决方案 »

  1.   

    <body>
       <asp:label id="dis" runat=server/>
         <form enctype="multipart/form-data" runat=server>          <h3>          Select File To Upload: <input id="UploadFile" type=file runat=server>          <asp:button Text="Upload Me!" OnClick="UploadBtn_Click" runat=server/>          <hr>
          
              <asp:panel id="ImageEditor" Visible=false runat=server>             <img ID="Image1" src="" runat="server"/>             <h3>
                    Image Width: <asp:textbox id="Width" runat=server/>                 Image Height: <asp:textbox id="Height" runat=server/> <br/>                 Text Caption: <asp:textbox id="Caption" runat=server/>                 Caption Size: <asp:dropdownlist id="FontSize" runat=server>
                                             <asp:listitem>14</asp:listitem>
                                             <asp:listitem>18</asp:listitem>
                                             <asp:listitem>26</asp:listitem>
                                             <asp:listitem>36</asp:listitem>
                                             <asp:listitem>48</asp:listitem>
                                             <asp:listitem>62</asp:listitem>
                                          </asp:dropdownlist>
                     Caption Font: <asp:dropdownlist id="FontType" runat=server>
                                             <asp:listitem>黑体</asp:listitem>
                                             <asp:listitem>仿宋</asp:listitem>
                                             <asp:listitem>隶书</asp:listitem>
                                             <asp:listitem>楷书</asp:listitem>
                                             <asp:listitem>方正姚体</asp:listitem>
                                             <asp:listitem>华文彩云</asp:listitem>
                                          </asp:dropdownlist>
                                                    
                     <asp:button Text="Update Image" OnClick="UpdateBtn_Click" runat=server/>             </h3> 
              </asp:panel>      </form>   </body>
    </html>
      

  2.   

    谢谢goody9807,可是还是一样,而且错误也是同样的,就是sFileName = Path.GetFileName(UploadFile.PostedFile.FileName);这句出错误,也就是UploadFile.PostedFile.FileName这个表达式出现错误。
      

  3.   

    http://dotnet.aspx.cc/ShowDetail.aspx?id=58EA3515-36F2-4FD9-AC89-EAF49F59816C
      

  4.   

    http://dotnet.aspx.cc/ShowDetail.aspx?id=45E7E33C-F149-450E-B5D5-832958C20538http://dotnet.aspx.cc/Exam/Thumbnail.aspx
      

  5.   

    先判断有没有上传东西先if (fileText.PostedFile.ContentLength > 0)
    {
        ...............
    }
      

  6.   

    谢谢大家的帮助,看来是我系统的问题吧,只要是fileText.PostedFile后面的方法与属性,通通报错!都是未将对象引用设置到对象的实例。
      

  7.   

    兄弟那段代码不应该写在imbSubmit_Click事件里,因为该事件触发时会与服务器交互,即重新走一遍page_load,而此时你的fileText已经不保存你上传文件的信息了。想得到上传的文件名什么的就写在fileText控件的事件里吧
      

  8.   

    多谢 goody9807、 net_lover、 xueqs的帮助,问题终于解决了,复制了孟子E章的代码。谢谢大家了。