server.mappath

Server.MapPath returning a path with a folder that doesn’t exists

你离开我真会死。 提交于 2020-01-15 19:13:38
问题 I have following code: var dir = @"Content\Posts\" + yr + @"\" + mnth + @"\"; var a = Path.Combine(dir, dy.ToString() + pId.ToString() + ".txt"); //a contains: "Content\\Posts\\2013\\8\\file01.txt" stts = obj.NotifyMail(title, writeup, "author@gmail.com", a); And than in NotifyMail function I have this: public bool NotifyMail(string subject, string body, string toAdd, string filePath) { … string attachments = HttpContext.Current.Server.MapPath(filePath); //NOW here attachments contains: "G:\

Server.MapPath returning a path with a folder that doesn’t exists

社会主义新天地 提交于 2020-01-15 19:12:30
问题 I have following code: var dir = @"Content\Posts\" + yr + @"\" + mnth + @"\"; var a = Path.Combine(dir, dy.ToString() + pId.ToString() + ".txt"); //a contains: "Content\\Posts\\2013\\8\\file01.txt" stts = obj.NotifyMail(title, writeup, "author@gmail.com", a); And than in NotifyMail function I have this: public bool NotifyMail(string subject, string body, string toAdd, string filePath) { … string attachments = HttpContext.Current.Server.MapPath(filePath); //NOW here attachments contains: "G:\

How can I use Server.MapPath inside class library project

你离开我真会死。 提交于 2019-12-22 04:07:40
问题 I have a web application thet has a number of class library projects. Some example code below. public static class LenderBL { static string LenderXml { get { return "MyPathHere"; } } public static LenderColl GetLenders() { var serializer = new XmlSerializer(typeof(LenderColl)); using (XmlReader reader = XmlReader.Create(LenderXml)) { return (LenderColl)serializer.Deserialize(reader); } } } I would normally use Server.MapPath to get the path for the property LenderXml, but when I use it in a

How can I use Server.MapPath inside class library project

我只是一个虾纸丫 提交于 2019-12-22 04:07:16
问题 I have a web application thet has a number of class library projects. Some example code below. public static class LenderBL { static string LenderXml { get { return "MyPathHere"; } } public static LenderColl GetLenders() { var serializer = new XmlSerializer(typeof(LenderColl)); using (XmlReader reader = XmlReader.Create(LenderXml)) { return (LenderColl)serializer.Deserialize(reader); } } } I would normally use Server.MapPath to get the path for the property LenderXml, but when I use it in a

ASP.NET MVC Server.MapPath giving full path in Internet Explorer

▼魔方 西西 提交于 2019-12-20 06:17:14
问题 I am uploading a file with var filename = Server.MapPath(Path.Combine("~/Content/UserContent", Path.ChangeExtension(newName,Path.GetExtension(attachments.FileName)))); attachments.SaveAs(filename); it works great except that in Internet Explorer it gives the full path "C:\Users\okke\Desktop\GEWOONEENMAP OK\etags.txt" instead of just saying "etags.txt", how can I fix this? 回答1: Call Path.GetFileName on the result to get only the file name e.g. attachments.SaveAs(Path.GetFileName(fileName)); If

How can I use Server.MapPath() from global.asax?

蹲街弑〆低调 提交于 2019-12-18 09:59:26
问题 I need to use Server.MapPath() to combine some files path that I store in the web.config . However, since Server.MapPath() relies on the current HttpContext (I think), I am unable to do this. When trying to use the method, even though its "available", I get the following exception: Server operation is not available in this context. Is there another method that can map a web root relative directory such as ~/App_Data/ to the full physical path such as C:\inetpub\wwwroot\project\App_data\ ? 回答1

Use Server.MapPath in Business Layer

限于喜欢 提交于 2019-12-14 03:41:29
问题 My business layer creates files and needs to save them in the App_Data folder of my asp.net mvc 4 web frontend. I could use Server.MapPath in the business layer to get the physical path of the App_Data folder. But i want to avoid a reference to System.Web in the business layer. Are there other ways to get the path to App_Data in business layer? 回答1: The correct way to deal with this is to have the presentation layer pass the path into the business layer. To put this another way, the purpose

Virtual Path in ASP.NET

做~自己de王妃 提交于 2019-12-13 05:18:27
问题 I am using this code for my LinkButton to download a file when you click on it. Recently i got this problem, i need a virtual path . I would like to redirect to C:\inetpub\wwwroot string filepath = Server.MapPath("..."); FileInfo myfile = new FileInfo(filepath); So I don't know what to put in Server.MapPath() because if I put / it will go to the base of my folder documents and no In 回答1: If you need to serve files from another part of your system then the best way to do this is to create a

System.UnauthorizedAccessException loading file from Disk

 ̄綄美尐妖づ 提交于 2019-12-11 05:26:55
问题 Really weird problem loading a file from disk: string path = HttpContext.Current.Server.MapPath("~/Datasets/blob.xml"); FileStream stream = new FileStream(path, FileMode.Open); Throws exception: An exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll but was not handled in user code Additional information: Access to the path 'D:\webroot\afob\Dev\v1.0.x\AFOB\Datasets\blob.xml' is denied. The strange thing is it was working 5 minutes ago. I checked permissions on the

Classic ASP Server.MapPath() doesn't work as expected in global.asa

浪尽此生 提交于 2019-12-10 11:23:34
问题 In Classic ASP, Server.MapPath() doesn't always work properly in the Application_OnStart event within global.asa . I have an ASP page at "\testfolder\test.asp" within a virtual root, I have an XSLT file at "\xsl\transform.xsl" . My virtual root is located in "c:\inetpub\wwwroot\testapp\" . I use MapPath within the ASP page to get the full path to the XSLT file. The call is: sXslPath = Server.MapPath("xsl\transform.xsl") Some times MapPath returns "c:\inetpub\wwwroot\testapp\xsl\transform.xsl"