The problem is you named the DownloadFile() method's input parameter "Path". Use the fully qualified name to get the file name.
System.IO.Path.GetFileName(str1);
https://learn.microsoft.com/en-us/dotnet/api/system.io.path?view=net-6.0
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
'String' does not contain a definition for GetFileName and no accessible extension method 'GetFileName' accepting a first argument of type 'string' could be found/are you missing a using directive or an assembly reference. I am getting error in GetFileName
[WebMethod]
public static string DownloadFile(string Path)
{
string str1 = Uri.UnescapeDataString(Path);
string fileName = Path.GetFileName(str1);
string str2 = "Result : " + DateTime.Now.ToString() + " - From Server";
FileInfo fileInfo = new FileInfo(HttpContext.Current.Server.MapPath("~/UploadFile/") + fileName);
HttpContext.Current.Response.ContentType = "APPLICATION/OCTET-STREAM";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "Attachment; Filename=" + fileName);
HttpContext.Current.Response.WriteFile(str1);
HttpContext.Current.Response.End();
return "true";
}
The problem is you named the DownloadFile() method's input parameter "Path". Use the fully qualified name to get the file name.
System.IO.Path.GetFileName(str1);
https://learn.microsoft.com/en-us/dotnet/api/system.io.path?view=net-6.0
DownloadFile (string Path)
As the error message clearly says, your variable "Path" is of type string and a string variable has no method GetFileName.
Hi @SathyanarayananAV ,
You just need to change the string Path to string path. The string you defined conflicts with the method name.
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.