你调用的对象是空的
我收到一个关于 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想尝试以下操作:
并获取选定的值,例如:
仅供参考:确保在上传文件时创建的路径中有正确的斜杠 (/)。
You might want to try this:
And get the selected value like:
FYI: Make sure there are proper slashes(/) in the path you are creating while uploading the file.