简体   繁体   English

使用C#的Windows Phone应用程序中的文件大小限制

[英]File size limit in Windows Phone application using C#

I am new in Windows Phone application. 我是Windows Phone应用程序的新手。 In my application, when uploading files it is required to add file size limit not exceeding 50kb. 在我的应用程序中,上传文件时,需要添加文件大小限制,不得超过50kb。

Code: 码:

public sealed class OpenFileDialog
{
    public string Filter { get; set; }

    internal static object ShowDialog()
    {
        throw new NotImplementedException();
    }
    public static object DialogResult { get; set; }
    public static string FileName { get; set; }
}

if (OpenFileDialog.ShowDialog() == System.Windows.Controls.DialogResult.OK)
{
    FileStream fs = File.OpenRead(OpenFileDialog.FileName);
    if (fs.Length > 51200)
    {
        MessageBox.Show("Image size must not exceed 50kb.");
        return;
    }
    System.Windows.Controls.Image myImage = new System.Windows.Controls.Image();
    myImage.Source = bmp;
}

but it show error, 但显示错误

Error: 错误:

namespace dialogresult doesn't exist in the namespace system.windows.controls(missing a assembly reference)

Anybody help me to solve this error? 有人帮我解决这个错误吗?

You're attempting to use an enumeration that is part of the System.Windows.Forms namespace, and no such open file dialog exists in the Windows Phone 8 library. 您正在尝试使用System.Windows.Forms命名空间一部分的枚举,并且Windows Phone 8库中没有这样的打开文件对话框。 Without knowing more about your file access scenario, I will point out that your options would include: 在不了解您的文件访问方案的更多信息的情况下,我将指出您的选择将包括:

  • Application Isolated Storage 应用隔离存储
  • Known Folders (WP 8.1 only including music, videos, photos, and SD card storage) 已知文件夹(仅WP 8.1包括音乐,视频,照片和SD卡存储)

I'll point you to this general guide to accessing files programmatically which may take you to where you need to be specifically, but I should point out that since the most commonly accessible files on a phone device are rarely 50kb or less in size, we likely need more information about your use case. 我将向您指出该以编程方式访问文件的一般指南 ,该指南可能会将您带到需要特别注意的地方,但是我应该指出,由于电话设备上最常访问的文件大小很少为50kb或更小,因此可能需要有关您的用例的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM