Skip to content

Commit 33eb7ea

Browse files
authored
Merge pull request #159 from Sososlik/patch-1
Fix for browsers sending the complete file path
2 parents 76c478e + f70326c commit 33eb7ea

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

c#/HomeController.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public ActionResult UploadFile()
2626
string category = HttpContext.Request.Params["category"];
2727

2828
DirectoryInfo di = Directory.CreateDirectory(Server.MapPath("~/Tmp/Files"));// If you don't have the folder yet, you need to create.
29-
string savedFileName = Path.Combine(di.FullName, hpf.FileName);
29+
string sentFileName = Path.GetFileName(hpf.FileName); //it can be just a file name or a user local path! it depends on the used browser. So we need to ensure that this var will contain just the file name.
30+
string savedFileName = Path.Combine(di.FullName, sentFileName);
3031
hpf.SaveAs(savedFileName);
3132

3233
var msg = new { msg = "File Uploaded", filename = hpf.FileName, url= savedFileName };
@@ -64,4 +65,4 @@ public ActionResult DeleteFile(string url)
6465
}
6566
}
6667
}
67-
}
68+
}

0 commit comments

Comments
 (0)