C # form implementation file upload

Source: Internet
Author: User
<form runat= "Server" id= "MyForm" > <table> <tr> <td align= "right" > Unit name:</td> <td
        Align= "Left" > <asp:textbox id= "txtname" runat= "Server" width= "150px" ></asp:TextBox> </td> <td > Type:</td> <td align= "left" > <asp:dropdownlist id= "Ddltype" runat=
                "Server" width= "150px" > <asp:listitem value= "true" selected= "true" > Text link </asp:ListItem> <asp:listitem value= "false" > Photo links </asp:ListItem> </asp:DropDownList>
                ;/td> </tr> <tr> <td align= "right" > Unit type:</td> <td align= "left" > <asp:dropdownlist id= "Ddlcooperatetype" runat= "Server" width= "150px" > <asp:listitem value=
            "0" > University </asp:ListItem> <asp:listitem value= "1" selected= "True" > Enterprise </asp:ListItem> </asp:dropdowNlist> </td> <td > ordered:</td> <td align= "left" > <asp:textbox id= "
					
		Txtsort "runat=" Server "width=" 150px "text=" 0 "></asp:TextBox> </td> </tr> <tr> &LT;TD > Links:</td> <td align= "left" > <asp:textbox id= "txtlink" runat= "Server" Heig ht= "17px" width= "150px" text= "http://www.qk12333.com" ></asp:TextBox> <as P:regularexpressionvalidator id= "RegularExpressionValidator1" runat= "Server" Controltovalidat E= "Txtlink" errormessage= is not in the correct format. "Forecolor=" Red "validationexpression=" http (s)?:/ /([\w-]+\.) +[\w-]+ (/[\w-/?%&=]*)? "  ></asp:RegularExpressionValidator> </td> <td > Image upload:</td> <td align= "left" > <asp:fileupload id= "fileupimage" runat= "Server" width= "244px"/> </td> </tr> <tr> <td align=" right "> Related description:</td> &LT;TD align= "left" colspan= "3" > <asp:textbox id= "txtdesc" runat= "Server" textmode= "MultiLine" width= "60 0 "height=" 128 "></asp:TextBox> </td> </tr> <tr> <td colspan = "4" align= "center" > <asp:button id= "btnfriendlink" runat= "Server" text= "Submit" Oncl 
                ick= "Btnfriendlink_click"/> <asp:button id= "Btnrestfriendlink" runat= "Server" text= "reset" onclick= "Btnrestfriendlink_click"/> </td> </tr> </table> </form>

    protected void Btnfriendlink_click (object sender, EventArgs e) {if (txtName.Text = "" | | txtName.Text = = null) {this. Clientscript.registerstartupscript (this. GetType (), "", "<script>alert (' unit name cannot be empty.
            ');</script> ");
        Return } string message = String.
        Empty; String imagesrc = String.
        Empty; Picture link, need to upload if (Ddltype.selectedvalue = = "false" | | (fileupimage.filename!=null&&fileupimage.filename!=string. Empty)) {string imagename = DateTime.Now.ToFileTime ().
            ToString (); if (imagename = = "" | | ImageName = = null) {this. Clientscript.registerstartupscript (this. GetType (), "" "," <script>alert (' please select a picture.
                ') </script> ");
            Return
            String contentType = Imagename.substring (Imagename.lastindexof (".") + 1); String folderpath = Server.MapPath ("..
            /uploadfile/friendlink/"); If (!
            Directory.Exists (FolderPath)) {directory.createdirectory (FolderPath); String path = Server.MapPath ("...").
            /uploadfile/friendlink/") + imagename; IMAGESRC = "uploadfile/friendlink/" + imagename + "." + fileUpImage.FileName.Substring (
            FileUpImage.FileName.LastIndexOf (".") + 1);;
        Uploadfile.upload (fileupimage, path, ref message);
        } Friendslink upimage = Inserttofriendslink (IMAGESRC); if (upimage = = null) {this. Clientscript.registerstartupscript (this. GetType (), "", "<script>alert (' Add failed.
            ') </script> ");
        Return
            else {reset (); This. Clientscript.registerstartupscript (this. GetType (), "", "<script>alert (' Add success.
        ') </script> "); } Private Friendslink Inserttofriendslink (string imagesrc) {Friendslink Friendslink = new Frie
        Ndslink (); Friendslink.
        Name = Stringsub.subtitle (txtName.Text);
        Friendslink.link = Txtlink.text;
        Friendslink.desc = Stringsub.subdescription (TxtDesc.Text.Trim ());
        FRIENDSLINK.IMAGESRC = IMAGESRC;
        Friendslink.sortid = Convert.ToInt32 (Txtsort.text);
        Friendslink.cooperatetype = Convert.ToInt32 (Ddlcooperatetype.selectedvalue);
        Friendslink.linktype = Convert.toboolean (Ddltype.selectedvalue);
    
    Return Friendslinkmanager.addfriendslink (Friendslink); }


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.