你调用的对象是空的

发布于 2024-11-14 11:06:02 字数 1340 浏览 0 评论 0原文

我收到一个关于 aspx 上传控件的错误单个 aspx 页面上的下拉列表。

这是错误...

Object reference not set to an instance of an object.

这是我的 on_submit 代码...

protected void ASPxUploadControl1_FileUploadComplete(object sender, DevExpress.Web.ASPxUploadControl.FileUploadCompleteEventArgs e)
    {
        if (e.IsValid)
        {
            string uploadDirectory = Server.MapPath("~/files/");
            //string uploadDirectory = "//DOCSD9F1/TECHDOCS/";

            string uploadFolder = DropDownList1.SelectedItem.Text;

            string fileName = e.UploadedFile.FileName;

            string path = (uploadDirectory + uploadFolder + fileName);

            e.UploadedFile.SaveAs(path);
            e.CallbackData = fileName;
        }
    }`

这是我用于创建下拉列表的代码...

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DirectoryInfo di = new DirectoryInfo("D:/SMGUpload/SMGUpload/files");

            DropDownList1.DataSource = di.GetDirectories();

            DropDownList1.DataBind();

            foreach (DirectoryInfo i in di.GetDirectories())
            {
                DropDownList1.DataTextField = i.FullName;
                DropDownList1.DataValueField = i.FullName;
            }
        }
    }`

I am getting an error with an aspx Upload Control & Drop Down List on a single aspx page.

Here is the error...

Object reference not set to an instance of an object.

Here is my code for the on_submit...

protected void ASPxUploadControl1_FileUploadComplete(object sender, DevExpress.Web.ASPxUploadControl.FileUploadCompleteEventArgs e)
    {
        if (e.IsValid)
        {
            string uploadDirectory = Server.MapPath("~/files/");
            //string uploadDirectory = "//DOCSD9F1/TECHDOCS/";

            string uploadFolder = DropDownList1.SelectedItem.Text;

            string fileName = e.UploadedFile.FileName;

            string path = (uploadDirectory + uploadFolder + fileName);

            e.UploadedFile.SaveAs(path);
            e.CallbackData = fileName;
        }
    }`

here is my code for creating the drop down list...

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DirectoryInfo di = new DirectoryInfo("D:/SMGUpload/SMGUpload/files");

            DropDownList1.DataSource = di.GetDirectories();

            DropDownList1.DataBind();

            foreach (DirectoryInfo i in di.GetDirectories())
            {
                DropDownList1.DataTextField = i.FullName;
                DropDownList1.DataValueField = i.FullName;
            }
        }
    }`

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

镜花水月 2024-11-21 11:06:02

您可能想尝试以下操作:

if(!Page.IsPostBack){
    DirectoryInfo di = new DirectoryInfo("D:/SMGUpload/SMGUpload/files");
    DirectoryInfo[] diArr = di.GetDirectories();
    DropDownList1.DataSource = diArr;
    DropDownList1.DataTextField = "Name";
    DropDownList1.DataValueField = "Name";
    DropDownList1.DataBind();
}

并获取选定的值,例如:

string uploadFolder = DropDownList1.SelectedValue;

仅供参考:确保在上传文件时创建的路径中有正确的斜杠 (/)。

You might want to try this:

if(!Page.IsPostBack){
    DirectoryInfo di = new DirectoryInfo("D:/SMGUpload/SMGUpload/files");
    DirectoryInfo[] diArr = di.GetDirectories();
    DropDownList1.DataSource = diArr;
    DropDownList1.DataTextField = "Name";
    DropDownList1.DataValueField = "Name";
    DropDownList1.DataBind();
}

And get the selected value like:

string uploadFolder = DropDownList1.SelectedValue;

FYI: Make sure there are proper slashes(/) in the path you are creating while uploading the file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文