客户端访问服务器端方法(客户端引入服务器端类)

本文介绍如何使用FreeTextBox实现图片上传功能,并根据用户不同上传到指定文件夹。文章详细展示了代码实现过程,包括文件验证、上传处理及界面展示。
首先声明这个是我在使用FreeTextBox时遇到了这个控件把所有的服务器端代码写到客户端,
代码如下:
None.gif
None.gif
< script runat = " server " >
None.gif
None.gif
//  Messages
None.gif
private   string  NoFileMessage  =   " 您没有选择文件。 " ;
None.gif
private   string  UploadSuccessMessage  =   " 上传成功 " ;
None.gif
private   string  UploadFailureMessage  =   " 上传失败。 " ;
None.gif
private   string  NoImagesMessage  =   " 该文件夹不存在或者是空的 " ;
None.gif
private   string  NoFolderSpecifiedMessage  =   " 您要上传到的文件夹不存在。 " ;
None.gif
private   string  NoFileToDeleteMessage  =   " 您没有选中要删除的文件。 " ;
None.gif
private   string  InvalidFileTypeMessage  =   " 您无法上传这种类型的文件。 " ;
ExpandedBlockStart.gifContractedBlock.gif
private   string [] AcceptedFileTypes  =   new   string []  dot.gif {"jpg","jpeg","jpe","gif","png"} ;
None.gif
None.gif
//  Configuration
None.gif
private   bool     UploadIsEnabled  =   true ;          //  是否允许上传文件
None.gif
private   bool     DeleteIsEnabled  =   true ;          //  是否允许删除文件
None.gif
private   string     DefaultImageFolder  = "defaultFolder" ;   //  默认的起始文件夹
None.gif

ExpandedBlockStart.gifContractedBlock.gif
private   void  Page_Load( object  sender, System.EventArgs e)  dot.gif {
InBlock.gif    
string isframe = "" + Request["frame"];
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if (isframe != ""dot.gif{
InBlock.gif        MainPage.Visible 
= true;
InBlock.gif        iframePanel.Visible 
= false;
InBlock.gif    WebForm1 wf
=new WebForm1();
InBlock.gif        
string rif = "" + Request["rif"];
InBlock.gif        
string cif = "" + Request["cif"];    
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if (cif != "" && rif != ""dot.gif{
InBlock.gif            RootImagesFolder.Value 
= DefaultImageFolder;
InBlock.gif            CurrentImagesFolder.Value 
= DefaultImageFolder;    
ExpandedSubBlockEnd.gif        }

InBlock.gif        UploadPanel.Visible 
= UploadIsEnabled;
InBlock.gif        DeleteImage.Visible 
= DeleteIsEnabled;
InBlock.gif
InBlock.gif        
string FileErrorMessage = "";
InBlock.gif        
string ValidationString = ".*(";
InBlock.gif        
//[\.jpg]|[\.jpeg]|[\.jpe]|[\.gif]|[\.png])$"
ExpandedSubBlockStart.gifContractedSubBlock.gif
        for (int i=0;i<AcceptedFileTypes.Length; i++dot.gif{
InBlock.gif            ValidationString 
+= "[\\." + AcceptedFileTypes[i] + "]";
InBlock.gif            
if (i < (AcceptedFileTypes.Length-1)) ValidationString += "|";
InBlock.gif            FileErrorMessage 
+= AcceptedFileTypes[i];
InBlock.gif            
if (i < (AcceptedFileTypes.Length-1)) FileErrorMessage += "";
ExpandedSubBlockEnd.gif        }

InBlock.gif        FileValidator.ValidationExpression 
= ValidationString+")$";
InBlock.gif        FileValidator.ErrorMessage
=FileErrorMessage;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if (!IsPostBack) dot.gif{
InBlock.gif            
InBlock.gif        
InBlock.gif        DisplayImages();
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif    }
 else dot.gif{
InBlock.gif        
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
public   void  UploadImage_OnClick( object  sender, EventArgs e)  dot.gif {    
ExpandedSubBlockStart.gifContractedSubBlock.gif    
if (Page.IsValid) dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if (CurrentImagesFolder.Value != ""dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
if (UploadFile.PostedFile.FileName.Trim() != ""dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif                
if (IsValidFileType(UploadFile.PostedFile.FileName)) dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
try dot.gif{
InBlock.gif                        
string UploadFileName = "";
InBlock.gif                        
string UploadFileDestination = "";
InBlock.gif                        UploadFileName 
= UploadFile.PostedFile.FileName;
InBlock.gif                        UploadFileName 
= UploadFileName.Substring(UploadFileName.LastIndexOf("\\")+1);
InBlock.gif                        UploadFileDestination 
= HttpContext.Current.Request.PhysicalApplicationPath;
InBlock.gif                        UploadFileDestination 
+= CurrentImagesFolder.Value;
InBlock.gif                        UploadFileDestination 
+= "\\";
InBlock.gif                        UploadFile.PostedFile.SaveAs(UploadFileDestination 
+ UploadFileName);
InBlock.gif                        ResultsMessage.Text 
= UploadSuccessMessage;
ExpandedSubBlockStart.gifContractedSubBlock.gif                    }
 catch(Exception ex) dot.gif{
InBlock.gif                        
//ResultsMessage.Text = "Your file could not be uploaded: " + ex.Message;
InBlock.gif
                        ResultsMessage.Text = UploadFailureMessage;
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockStart.gifContractedSubBlock.gif                }
 else dot.gif{
InBlock.gif                    ResultsMessage.Text 
= InvalidFileTypeMessage;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockStart.gifContractedSubBlock.gif            }
 else dot.gif{
InBlock.gif                ResultsMessage.Text 
= NoFileMessage;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockStart.gifContractedSubBlock.gif        }
 else dot.gif{
InBlock.gif            ResultsMessage.Text 
= NoFolderSpecifiedMessage;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif    }
 else dot.gif{
InBlock.gif        ResultsMessage.Text 
= InvalidFileTypeMessage;
InBlock.gif        
ExpandedSubBlockEnd.gif    }

InBlock.gif    DisplayImages();
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
public   void  DeleteImage_OnClick( object  sender, EventArgs e)  dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
if (FileToDelete.Value != "" && FileToDelete.Value != "undefined"dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
try dot.gif{
InBlock.gif            
string AppPath = HttpContext.Current.Request.PhysicalApplicationPath;
InBlock.gif            System.IO.File.Delete(AppPath  
+ CurrentImagesFolder.Value + "\\" + FileToDelete.Value);
InBlock.gif            ResultsMessage.Text 
= "已删除: " + FileToDelete.Value;
ExpandedSubBlockStart.gifContractedSubBlock.gif        }
 catch(Exception ex) dot.gif{            
InBlock.gif            ResultsMessage.Text 
= "删除失败。";
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif    }
 else dot.gif{
InBlock.gif        ResultsMessage.Text 
= NoFileToDeleteMessage;
ExpandedSubBlockEnd.gif    }

InBlock.gif    DisplayImages();
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
private   bool  IsValidFileType( string  FileName)  dot.gif {
InBlock.gif    
string ext = FileName.Substring(FileName.LastIndexOf(".")+1,FileName.Length-FileName.LastIndexOf(".")-1);
ExpandedSubBlockStart.gifContractedSubBlock.gif    
for (int i=0; i<AcceptedFileTypes.Length; i++dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if (ext == AcceptedFileTypes[i]) dot.gif{
InBlock.gif            
return true;
InBlock.gif            
ExpandedSubBlockEnd.gif        }
    
ExpandedSubBlockEnd.gif    }

InBlock.gif    
return false;
ExpandedBlockEnd.gif}

None.gif
None.gif
ExpandedBlockStart.gifContractedBlock.gif
private   string [] ReturnFilesArray()  dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
if (CurrentImagesFolder.Value != ""dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
try dot.gif{
InBlock.gif            
string AppPath = HttpContext.Current.Request.PhysicalApplicationPath;
InBlock.gif            
string ImageFolderPath = AppPath + CurrentImagesFolder.Value;
InBlock.gif            
string[] FilesArray = System.IO.Directory.GetFiles(ImageFolderPath,"*");
InBlock.gif            
return FilesArray;
InBlock.gif            
InBlock.gif            
ExpandedSubBlockStart.gifContractedSubBlock.gif        }
 catch dot.gif{
InBlock.gif        
InBlock.gif            
return null;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif    }
 else dot.gif{
InBlock.gif        
return null;
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
private   string [] ReturnDirectoriesArray()  dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
if (CurrentImagesFolder.Value != ""dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
try dot.gif{
InBlock.gif            
string AppPath = HttpContext.Current.Request.PhysicalApplicationPath;
InBlock.gif            
string CurrentFolderPath = AppPath + CurrentImagesFolder.Value;
InBlock.gif            
string[] DirectoriesArray = System.IO.Directory.GetDirectories(CurrentFolderPath,"*");
InBlock.gif            
return DirectoriesArray ;
ExpandedSubBlockStart.gifContractedSubBlock.gif        }
 catch dot.gif{
InBlock.gif            
return null;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif    }
 else dot.gif{
InBlock.gif        
return null;
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
public   void  DisplayImages()  dot.gif {
InBlock.gif    
string[] FilesArray = ReturnFilesArray();
InBlock.gif    
string[] DirectoriesArray = ReturnDirectoriesArray();
InBlock.gif    
string AppPath = HttpContext.Current.Request.PhysicalApplicationPath;
InBlock.gif    
string AppUrl;
InBlock.gif    
InBlock.gif    
//Get the application's URL
InBlock.gif
    if (Request.ApplicationPath == "/")
InBlock.gif        AppUrl 
= Request.ApplicationPath;
InBlock.gif    
else
InBlock.gif        AppUrl 
= Request.ApplicationPath + "/";
InBlock.gif    
InBlock.gif    GalleryPanel.Controls.Clear();
ExpandedSubBlockStart.gifContractedSubBlock.gif    
if ( (FilesArray == null || FilesArray.Length == 0&& (DirectoriesArray == null || DirectoriesArray.Length == 0) ) dot.gif{
InBlock.gif        gallerymessage.Text 
= NoImagesMessage + "" + RootImagesFolder.Value;
ExpandedSubBlockStart.gifContractedSubBlock.gif    }
 else dot.gif{
InBlock.gif        
string ImageFileName = "";
InBlock.gif        
string ImageFileLocation = "";
InBlock.gif
InBlock.gif        
int thumbWidth = 94;
InBlock.gif        
int thumbHeight = 94;
InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if (CurrentImagesFolder.Value != RootImagesFolder.Value) dot.gif{
InBlock.gif
InBlock.gif            System.Web.UI.HtmlControls.HtmlImage myHtmlImage 
= new System.Web.UI.HtmlControls.HtmlImage();
InBlock.gif            myHtmlImage.Src 
= AppUrl + "../images/ftb/folder.up.gif";
InBlock.gif            myHtmlImage.Attributes[
"unselectable"]="on"
InBlock.gif            myHtmlImage.Attributes[
"align"]="absmiddle"
InBlock.gif            myHtmlImage.Attributes[
"vspace"]="36"
InBlock.gif
InBlock.gif            
string ParentFolder = CurrentImagesFolder.Value.Substring(0,CurrentImagesFolder.Value.LastIndexOf("\\"));
InBlock.gif
InBlock.gif            System.Web.UI.WebControls.Panel myImageHolder 
= new System.Web.UI.WebControls.Panel();                    
InBlock.gif            myImageHolder.CssClass 
= "imageholder";
InBlock.gif            myImageHolder.Attributes[
"unselectable"]="on"
InBlock.gif            myImageHolder.Attributes[
"onclick"]="divClick(this,'');";  
InBlock.gif            myImageHolder.Attributes[
"ondblclick"]="gotoFolder('" + RootImagesFolder.Value + "','" + ParentFolder.Replace("\\","\\\\"+ "');";  
InBlock.gif            myImageHolder.Controls.Add(myHtmlImage);
InBlock.gif
InBlock.gif            System.Web.UI.WebControls.Panel myMainHolder 
= new System.Web.UI.WebControls.Panel();
InBlock.gif            myMainHolder.CssClass 
= "imagespacer";
InBlock.gif            myMainHolder.Controls.Add(myImageHolder);
InBlock.gif
InBlock.gif            System.Web.UI.WebControls.Panel myTitleHolder 
= new System.Web.UI.WebControls.Panel();
InBlock.gif            myTitleHolder.CssClass 
= "titleHolder";
InBlock.gif            myTitleHolder.Controls.Add(
new LiteralControl("向上"));
InBlock.gif            myMainHolder.Controls.Add(myTitleHolder);
InBlock.gif
InBlock.gif            GalleryPanel.Controls.Add(myMainHolder);        
InBlock.gif            
ExpandedSubBlockEnd.gif        }

InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
foreach (string _Directory in DirectoriesArray) dot.gif{
InBlock.gif            
ExpandedSubBlockStart.gifContractedSubBlock.gif            
try dot.gif{
InBlock.gif                
string DirectoryName = _Directory.ToString();
InBlock.gif                
InBlock.gif
InBlock.gif                System.Web.UI.HtmlControls.HtmlImage myHtmlImage 
= new System.Web.UI.HtmlControls.HtmlImage();
InBlock.gif                myHtmlImage.Src 
= AppUrl + "../images/ftb/folder.big.gif";
InBlock.gif                myHtmlImage.Attributes[
"unselectable"]="on"
InBlock.gif                myHtmlImage.Attributes[
"align"]="absmiddle"
InBlock.gif                myHtmlImage.Attributes[
"vspace"]="29"
InBlock.gif
InBlock.gif                System.Web.UI.WebControls.Panel myImageHolder 
= new System.Web.UI.WebControls.Panel();                    
InBlock.gif                myImageHolder.CssClass 
= "imageholder";
InBlock.gif                myImageHolder.Attributes[
"unselectable"]="on"
InBlock.gif                myImageHolder.Attributes[
"onclick"]="divClick(this);";  
InBlock.gif                myImageHolder.Attributes[
"ondblclick"]="gotoFolder('" + RootImagesFolder.Value + "','" + DirectoryName.Replace(AppPath,"").Replace("\\","\\\\"+ "');";  
InBlock.gif                myImageHolder.Controls.Add(myHtmlImage);
InBlock.gif
InBlock.gif                System.Web.UI.WebControls.Panel myMainHolder 
= new System.Web.UI.WebControls.Panel();
InBlock.gif                myMainHolder.CssClass 
= "imagespacer";
InBlock.gif                myMainHolder.Controls.Add(myImageHolder);
InBlock.gif
InBlock.gif                System.Web.UI.WebControls.Panel myTitleHolder 
= new System.Web.UI.WebControls.Panel();
InBlock.gif                myTitleHolder.CssClass 
= "titleHolder";
InBlock.gif                myTitleHolder.Controls.Add(
new LiteralControl(DirectoryName.Replace(AppPath + CurrentImagesFolder.Value + "\\","")));
InBlock.gif                myMainHolder.Controls.Add(myTitleHolder);
InBlock.gif
InBlock.gif                GalleryPanel.Controls.Add(myMainHolder);        
ExpandedSubBlockStart.gifContractedSubBlock.gif            }
 catch dot.gif{
InBlock.gif                
// nothing for error
ExpandedSubBlockEnd.gif
            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
foreach (string ImageFile in FilesArray) dot.gif{
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif            
try dot.gif{
InBlock.gif
InBlock.gif                ImageFileName 
= ImageFile.ToString();
InBlock.gif                ImageFileName 
= ImageFileName.Substring(ImageFileName.LastIndexOf("\\")+1);
InBlock.gif                ImageFileLocation 
= AppUrl;
InBlock.gif                ImageFileLocation 
= ImageFileLocation.Substring(ImageFileLocation.LastIndexOf("\\")+1);
InBlock.gif                
//galleryfilelocation += "/";
InBlock.gif
                ImageFileLocation += CurrentImagesFolder.Value;
InBlock.gif                ImageFileLocation 
+= "/";
InBlock.gif                ImageFileLocation 
+= ImageFileName;
InBlock.gif                System.Web.UI.HtmlControls.HtmlImage myHtmlImage 
= new System.Web.UI.HtmlControls.HtmlImage();
InBlock.gif                myHtmlImage.Src 
= ImageFileLocation;
InBlock.gif                System.Drawing.Image myImage 
= System.Drawing.Image.FromFile(ImageFile.ToString());
InBlock.gif                myHtmlImage.Attributes[
"unselectable"]="on";  
InBlock.gif                
//myHtmlImage.border=0;
InBlock.gif
InBlock.gif                
// landscape image
ExpandedSubBlockStart.gifContractedSubBlock.gif
                if (myImage.Width > myImage.Height) dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
if (myImage.Width > thumbWidth) dot.gif{
InBlock.gif                        myHtmlImage.Width 
= thumbWidth;
InBlock.gif                        myHtmlImage.Height 
= Convert.ToInt32(myImage.Height * thumbWidth/myImage.Width);                        
ExpandedSubBlockStart.gifContractedSubBlock.gif                    }
 else dot.gif{
InBlock.gif                        myHtmlImage.Width 
= myImage.Width;
InBlock.gif                        myHtmlImage.Height 
= myImage.Height;
ExpandedSubBlockEnd.gif                    }

InBlock.gif                
// portrait image
ExpandedSubBlockStart.gifContractedSubBlock.gif
                }
 else dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
if (myImage.Height > thumbHeight) dot.gif{
InBlock.gif                        myHtmlImage.Height 
= thumbHeight;
InBlock.gif                        myHtmlImage.Width 
= Convert.ToInt32(myImage.Width * thumbHeight/myImage.Height);
ExpandedSubBlockStart.gifContractedSubBlock.gif                    }
 else dot.gif{
InBlock.gif                        myHtmlImage.Width 
= myImage.Width;
InBlock.gif                        myHtmlImage.Height 
= myImage.Height;
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif                
ExpandedSubBlockStart.gifContractedSubBlock.gif                
if (myHtmlImage.Height < thumbHeight) dot.gif{
InBlock.gif                    myHtmlImage.Attributes[
"vspace"= Convert.ToInt32((thumbHeight/2)-(myHtmlImage.Height/2)).ToString(); 
ExpandedSubBlockEnd.gif                }

InBlock.gif
InBlock.gif
InBlock.gif                System.Web.UI.WebControls.Panel myImageHolder 
= new System.Web.UI.WebControls.Panel();                    
InBlock.gif                myImageHolder.CssClass 
= "imageholder";
InBlock.gif                myImageHolder.Attributes[
"onclick"]="divClick(this,'" + ImageFileName + "');";  
InBlock.gif                myImageHolder.Attributes[
"ondblclick"]="returnImage('" + ImageFileLocation.Replace("\\","/"+ "','" + myImage.Width.ToString() + "','" + myImage.Height.ToString() + "');";  
InBlock.gif                myImageHolder.Controls.Add(myHtmlImage);
InBlock.gif
InBlock.gif
InBlock.gif                System.Web.UI.WebControls.Panel myMainHolder 
= new System.Web.UI.WebControls.Panel();
InBlock.gif                myMainHolder.CssClass 
= "imagespacer";
InBlock.gif                myMainHolder.Controls.Add(myImageHolder);
InBlock.gif
InBlock.gif                System.Web.UI.WebControls.Panel myTitleHolder 
= new System.Web.UI.WebControls.Panel();
InBlock.gif                myTitleHolder.CssClass 
= "titleHolder";
InBlock.gif                myTitleHolder.Controls.Add(
new LiteralControl(ImageFileName + "<BR>" + myImage.Width.ToString() + "x" + myImage.Height.ToString()));
InBlock.gif                myMainHolder.Controls.Add(myTitleHolder);
InBlock.gif
InBlock.gif                
//GalleryPanel.Controls.Add(myImage);
InBlock.gif
                GalleryPanel.Controls.Add(myMainHolder);
InBlock.gif                
InBlock.gif                myImage.Dispose();
ExpandedSubBlockStart.gifContractedSubBlock.gif            }
 catch dot.gif{
InBlock.gif
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        gallerymessage.Text 
= "";
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
</ script >
None.gif
< asp:panel id = " MainPage "  runat = " server "  visible = " false " >
None.gif
<! doctype html  public   " -//W3C//DTD HTML 4.0 Transitional//EN "   >
None.gif
< HTML >
None.gif
< HEAD >
None.gif
< META HTTP - EQUIV = " Expires "  CONTENT = " 0 " >
None.gif
< title > 插入图片 </ title >
None.gif
< style >
None.gif
ExpandedBlockStart.gifContractedBlock.gifbody 
dot.gif {
InBlock.gif    margin: 0px 0px 0px 0px;
InBlock.gif    padding: 0px 0px 0px 0px;
InBlock.gif    background: #ffffff; 
InBlock.gif    width: 
99.99%;
InBlock.gif    overflow:hidden;
InBlock.gif    border: 
0;
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gifbody,tr,td 
dot.gif {
InBlock.gif    color: #
000000;
InBlock.gif    font
-family: Verdana, Arial, Helvetica, sans-serif;
InBlock.gif    font
-size: 10pt;
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gifdiv.imagespacer 
dot.gif {
InBlock.gif    width: 
120;
InBlock.gif    height: 
126;
InBlock.gif    text
-align: center;            
InBlock.gif    
float: left;
InBlock.gif    font: 10pt verdana;
InBlock.gif    margin: 5px;
InBlock.gif    overflow: hidden;
ExpandedBlockEnd.gif}

ExpandedBlockStart.gifContractedBlock.gifdiv.imageholder 
dot.gif {
InBlock.gif    margin: 0px;
InBlock.gif    padding: 0px;
InBlock.gif    border: 
1 solid #CCCCCC;
InBlock.gif    width: 
100;
InBlock.gif    height: 
100;
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gifdiv.titleholder 
dot.gif {
InBlock.gif    font
-family: ms sans serif, arial;
InBlock.gif    font
-size: 8pt;
InBlock.gif    width: 
100;
InBlock.gif    text
-overflow: ellipsis;
InBlock.gif    overflow: hidden;
InBlock.gif    white
-space: nowrap;            
ExpandedBlockEnd.gif}
        
None.gif
None.gif
</ style >
None.gif
None.gif
None.gif
< script language = " javascript " >
None.gif
None.gif function GetPathByPeople() 
None.gif
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif
InBlock.gif        var re1
=UI_PUB_01.GetPath();
InBlock.gif    
InBlock.gif        document.getElementById(
"txtPath").value=re1.value
InBlock.gif        
//alert(document.getElementById("txtPath").value);
InBlock.gif
    
ExpandedBlockEnd.gif        }

None.gif            
None.giflastDiv 
=   null ;
ExpandedBlockStart.gifContractedBlock.giffunction divClick(theDiv,filename) 
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
if (lastDiv) dot.gif{
InBlock.gif        lastDiv.style.border 
= "1 solid #CCCCCC";
ExpandedSubBlockEnd.gif    }

InBlock.gif    lastDiv 
= theDiv;
InBlock.gif    theDiv.style.border 
= "2 solid #316AC5";
InBlock.gif    
InBlock.gif    document.getElementById(
"FileToDelete").value = filename;
InBlock.gif
ExpandedBlockEnd.gif}

ExpandedBlockStart.gifContractedBlock.giffunction gotoFolder(rootfolder,newfolder) 
dot.gif {
InBlock.gif    window.navigate(
"ftb.imagegallery.aspx?frame=1&rif=" + rootfolder + "&cif=" + newfolder);
ExpandedBlockEnd.gif}
        
ExpandedBlockStart.gifContractedBlock.giffunction returnImage(imagename,width,height) 
dot.gif {
InBlock.gif    var arr 
= new Array();
InBlock.gif    arr[
"filename"= imagename;  
InBlock.gif    arr[
"width"= width;  
InBlock.gif    arr[
"height"= height;             
InBlock.gif    window.parent.returnValue 
= arr;
InBlock.gif    window.parent.close();    
ExpandedBlockEnd.gif}
        
None.gif
</ script >         
None.gif
</ HEAD >
None.gif
< body  >
None.gif
< table width = 99.99 %  height = 99.99 %  cellpadding = 0  cellspacing = 0  border = 0 >
None.gif
None.gif
< FORM encType = " multipart/form-data "  runat = " server " >
None.gif
None.gif
< tr >< td >
None.gif    
< div id = " galleryarea "  style = " width=99.99%; height:99.99%; overflow: auto; " >
None.gif        
< asp:label id = " gallerymessage "  runat = " server " ></ asp:label >< asp:textbox id = " txtPath "  style = " Z-INDEX: 101; LEFT: 88px; display:none;POSITION: absolute; TOP: 160px "  runat = " server " > aaaa </ asp:textbox >
None.gif        
< asp:panel id = " GalleryPanel "  runat = " server " ></ asp:panel >
None.gif    
</ div >
None.gif
</ td ></ tr >
None.gif
< asp:Panel id = " UploadPanel "  runat = " server " >
None.gif
< tr >< td height = 16  style = " padding-left:10px;border-top: 1 solid #999999; background-color:#99ccff; " >
None.gif    
None.gif    
< table >
None.gif    
< tr >
None.gif        
< td valign = top >< input id = " UploadFile "  type = " file "  name = " UploadFile "  runat = " server "  style = " width:300; " /></ td >
None.gif        
< td valign = top >< asp:button id = " UploadImage "  Text = " 上传 "  runat = " server "  onclick = " UploadImage_OnClick "   /></ td >
None.gif        
< td valign = top >< asp:button id = " DeleteImage "  Text = " 删除 "  runat = " server "  onclick = " DeleteImage_OnClick "   /></ td >
None.gif        
< td valign = middle >         
None.gif    
</ tr >
None.gif    
< tr >
None.gif        
< td colspan = 3 >
None.gif            
< asp:RegularExpressionValidator runat = " server "  
None.gif                ControlToValidate
= " UploadFile "  
None.gif                id
= " FileValidator "  display = " dynamic " />
None.gif            
< asp:literal id = " ResultsMessage "  runat = " server "   />         
None.gif        
</ td >         
None.gif    
</ tr ></ table >     
None.gif    
< input type = " hidden "  id = " FileToDelete "  Value = ""  runat = " server "   />
None.gif    
< input type = " hidden "  id = " RootImagesFolder "  Value = " images "  runat = " server "   />
None.gif    
< input type = " hidden "  id = " CurrentImagesFolder "  Value = " images "  runat = " server "   />
None.gif
</ td ></ tr >
None.gif
</ asp:panel >
None.gif
</ form >
None.gif
</ table >
None.gif
</ body >
None.gif
</ HTML >
None.gif
</ asp:panel >
None.gif
< asp:panel id = " iframePanel "  runat = " server "   >
None.gif
< html >  
None.gif
< head >< title > 插入图片 </ title ></ head >
None.gif
< style >
ExpandedBlockStart.gifContractedBlock.gifbody 
dot.gif {
InBlock.gif    margin: 0px 0px 0px 0px;
InBlock.gif    padding: 0px 0px 0px 0px;
InBlock.gif    background: #ffffff;
InBlock.gif    overflow:hidden;
ExpandedBlockEnd.gif}

None.gif
</ style >
None.gif
< body  >
None.gif    
< iframe style = " width:99.99%;height:99.99%;border:0; "  border = 0  frameborder = 0  src = " ftb.imagegallery.aspx?frame=1&<%=Request.QueryString%> " ></ iframe >
None.gif
</ body >
None.gif
</ html >
None.gif
</ asp:panel >
None.gif

我想在其上传的时候根据不同的人上传到不同的文件夹,同时显示不同的文件夹。即是修改DefaultImageFolder文件夹名。刚开始的时候总想通过WebForm2 wf=new WebForm2();DefaultImageFolder=wf.GetPath();这种声明方式去访问WebForm2的GetPath方法,但总是出现以下错误提示: 找不到类型或命名空间名称“WebForm2”
根据他的提示我 在其中加入了对这个WEB项目的应用:

None.gif <% @ Import Namespace = " Telegnosis.Projects.TeleOA.Web "   %>

运行通过了,还达到了我预想的要求,这还是我第一次这样用,所以跟大家分享下。
点击这里下载DEMO

转载于:https://www.cnblogs.com/gjahead/archive/2007/04/25/727027.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值