2

InputFile.PostedFile.ContentLength で測定される単位を教えてください。ファイルが 500k 未満であることを確認する必要があります。

ありがとう。

4

3 に答える 3

11

測定単位 = バイト。

1 Kilobyte (kB) = 2ˆ10 Byte = 1024 Bytes

15 KB のファイル サイズのサンプル コード テスト:

const int maxFileLength = 15360; // 15KB = 1024 * 15

if(PictureFile.PostedFile.ContentLength > maxFileLength)
{

    MyResult.Text = String.Format("Your post has a size of {0:#,##0} bytes which
    exceeded the limit of {0:#,##0} bytes. Please upload a smaller file.",
    PictureFile.ContentLength, maxFileLength);
}
else
{
    // Save the file here
    MyResult.Text = "Thank you for posting."
}

あなたの場合、ファイルを 500 KB 未満にする必要があるため、次のようにする必要があります。

const int maxFileLength = 512000; // 500KB = 500 * 1024
于 2010-09-13T06:09:48.423 に答える
2

バイトです。

http://msdn.microsoft.com/en-us/library/system.web.httppostedfile.contentlength.aspx

HttpPostedFile.ContentLength

アップロードされたファイルのサイズをバイト単位で取得します。

于 2010-09-13T06:09:14.190 に答える
-1

画像

1 MB を超えるテンプレート ファイルをアップロードすると、長時間ロードされます。私のコードは次のとおりです----

if (checkImagecount())
{
    //string imgFolder = Server.MapPath("/Userimages/" + emp_id.ToString().Trim() + "/Images/Browseimage/");
    string destinationImage = Server.MapPath("/master/" + emp_id.ToString().Trim() + "/Images/");
    string destination1 = Server.MapPath("/master/" + emp_id.ToString().Trim() + "/Images/");
    string imgFilename, fileExt = String.Empty;
    Response.Write(fileTemplateimage.PostedFile.ContentLength+"<br/>");
    Response.Write(fileTemplateimage.FileBytes.Length);
    Response.End();    
    if (fileTemplateimage.PostedFile.ContentLength > 0 && fileTemplateimage.FileBytes.Length <= 1048576)
    {

        System.Drawing.Image uploadImage = System.Drawing.Image.FromStream(fileTemplateimage.PostedFile.InputStream);
        float uploadImagewidth = uploadImage.PhysicalDimension.Width;
        float uploadImageheight = uploadImage.PhysicalDimension.Height;
else
    {

        Page.ClientScript.RegisterStartupScript(this.GetType(), "failure", "alert('अपलोड फ़ाइल आकार 1 एमबी से अधिक नहीं होना चाहिए.');", true);
        divhide.Style.Add("display", "block");
        divUploadpanel.Style.Add("display", "block");
        fileTemplateimage.Focus();
于 2016-07-05T06:34:25.167 に答える