HtmlInputFile.MaxLength プロパティ
アセンブリ: System.Web (system.web.dll 内)

Dim instance As HtmlInputFile Dim value As Integer value = instance.MaxLength instance.MaxLength = value
ファイル パスの最大長。既定値は -1 です。このプロパティが設定されていないことを示します。

このプロパティを使用して、アップロードするファイルのパスとして入力できる最大文字数を指定します。
![]() |
---|
このプロパティがサポートされるかどうかは、ブラウザに依存します。使用するブラウザで、このプロパティがサポートされているかどうかを確認してください。 |

MaxLength プロパティを使用して、ファイル パスに入力できる文字数を制限する方法を次のコード例に示します。この例を正常に動作させるには、コンピュータの C: ドライブに Temp というディレクトリを作成する必要があります。
<%@ Page Language="VB" AutoEventWireup="True" %> <script language="VB" runat="server"> Sub Button1_Click(ByVal Source As Object, ByVal e As EventArgs) ' Make sure a file was submitted. If Text1.Value = "" Then Span1.InnerHtml = "Error: You must enter a file name." Return End If ' Save the file. If File1.PostedFile.ContentLength > 0 Then Try File1.PostedFile.SaveAs(("c:\temp\" & Text1.Value)) Span1.InnerHtml = "File uploaded successfully to <b>c:\temp\" & _ Text1.Value & "</b> on the Web server." Catch exc As Exception Span1.InnerHtml = "Error saving file <b>c:\temp\" & _ Text1.Value & "</b><br>" & exc.ToString() & "." End Try End If End Sub </script> <html> <head> <title>HtmlInputFile Example</title> </head> <body> <h3>HtmlInputFile Sample</h3> <form enctype="multipart/form-data" runat="server"> Select File to Upload: <input id="File1" type="file" maxlength="30" runat="server"/> <p> Save as file name (no path): <input id="Text1" type="text" runat="server"/> </p> <p> <span id=Span1 style="font: 8pt verdana;" runat="server" /> </p> <p> <input type=button id="Button1" value="Upload" onserverclick="Button1_Click" runat="server"> </p> </form> </body> </html>
<%@ Page Language="C#" AutoEventWireup="True" %> <script runat="server"> void Button1_Click(object Source, EventArgs e) { // Make sure a file was submitted. if (Text1.Value == "") { Span1.InnerHtml = "Error: You must enter a file name."; return; } // Save the file. if (File1.PostedFile.ContentLength > 0) { try { File1.PostedFile.SaveAs("c:\\temp\\" + Text1.Value); Span1.InnerHtml = "File uploaded successfully to <b>c:\\temp\\" + Text1.Value + "</b> on the Web server."; } catch (Exception exc) { Span1.InnerHtml = "Error saving file <b>c:\\temp\\" + Text1.Value + "</b><br>" + exc.ToString() + "."; } } Span1.InnerHtml = File1.MaxLength.ToString(); } </script> <html> <head> <title>HtmlInputFile Example</title> </head> <body> <h3>HtmlInputFile Sample</h3> <form enctype="multipart/form-data" runat="server"> Select File to Upload: <input id="File1" type="file" maxlength="30" runat="server"/> <p> Save as file name (no path): <input id="Text1" type="text" runat="server"/> </p> <p> <span id=Span1 style="font: 8pt verdana;" runat="server" /> </p> <p> <input type=button id="Button1" value="Upload" onserverclick="Button1_Click" runat="server"> </p> </form> </body> </html>
<%@ Page Language="JScript" AutoEventWireup="True" %> <script runat="server"> function Button1_Click(source : Object, e : EventArgs){ // Make sure a file was submitted. if(Text1.Value == "") { Span1.InnerHtml = "Error: You must enter a file name." return } // Save the file. if(File1.PostedFile.ContentLength > 0) { try { File1.PostedFile.SaveAs(("c:\\temp\\" + Text1.Value)) Span1.InnerHtml = "File uploaded successfully to <b>c:\\temp\\" + Text1.Value + "</b> on the Web server." } catch(exc : Exception) { Span1.InnerHtml = "Error saving file <b>c:\\temp\\" + Text1.Value + "</b><br>" + exc.ToString() + "." } } } </script> <html> <head> <title>HtmlInputFile Example</title> </head> <body> <h3>HtmlInputFile Sample</h3> <form enctype="multipart/form-data" runat="server"> Select File to Upload: <input id="File1" type="file" maxlength="30" runat="server"/> <p> Save as file name (no path): <input id="Text1" type="text" runat="server"/> </p> <p> <span id=Span1 style="font: 8pt verdana;" runat="server" /> </p> <p> <input type=button id="Button1" value="Upload" onserverclick="Button1_Click" runat="server"> </p> </form> </body> </html>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からHtmlInputFile.MaxLength プロパティを検索する場合は、下記のリンクをクリックしてください。

- HtmlInputFile.MaxLength プロパティのページへのリンク