以前我用FileUpload.PostFile.Filename就可以获取了,但是现在发现不行了,查了很多资料,最后谜底揭开了
原来是我IE浏览器的安全性太高了,在工具-->Inernet-->安全-->自定义级别-->启用 “将文件上载到服务器并包含本地路径”
OK...
获取不到客户端的路径 HttpContext.Current.Server.MapPath(服务器路径) 这会返回一个服务器的完整路径 FileUpload1.SaveAs(一个字符串,指定服务器上用于保存上载文件的位置的完整路径。)
服务器端是不能获取的。 你可以利用客户端的JS + Hidden Field ,间接获取
- Proposed As Answer by KristoferA - Huagati SystemsEditor Monday, August 02, 2010 5:36 AM
- Marked As Answer by Alex LiangModerator Thursday, August 05, 2010 3:18 AM
You can follow Marcel’s suggestion, use PredicateBuilder to implement what you need. Here is a complete example based on NorthWind database.
private void button1_Click(object sender, EventArgs e) { using (NorthWindDataContext ctx = new NorthWindDataContext()) { List<string> myListOfStrings = new List<string> { "fish", "Seaweed" }; var predicate = PredicateBuilder.False<Category>(); foreach (string keyword in myListOfStrings) { string temp = keyword; predicate = predicate.Or(p => p.Description.Contains(temp)); } IQueryable<Category> query = ctx.Categories.Where(predicate); //You can check the Commmand Text here Console.WriteLine(ctx.GetCommand(query).CommandText); this.dataGridView1.DataSource = query; } }
Below is the PredicateBuilder class.
public static class PredicateBuilder { public static Expression<Func<T, bool>> True<T>() { return f => true; } public static Expression<Func<T, bool>> False<T>() { return f => false; } public static Expression<Func<T, bool>> Or<T>(this Expression<Func<T, bool>> expr1, Expression<Func<T, bool>> expr2) { var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>()); return Expression.Lambda<Func<T, bool>> (Expression.OrElse(expr1.Body, invokedExpr), expr1.Parameters); } public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> expr1, Expression<Func<T, bool>> expr2) { var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>()); return Expression.Lambda<Func<T, bool>> (Expression.AndAlso(expr1.Body, invokedExpr), expr1.Parameters); } }
If you have other question, please feel free to let me know.
Best regards,
Alex Liang
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.