Commit dbf15746 authored by Krishna Reddy Tamatam's avatar Krishna Reddy Tamatam

Added Delete documnet function

parent e8b037e4
...@@ -159,7 +159,7 @@ namespace FTP_Services.Services.Controllers ...@@ -159,7 +159,7 @@ namespace FTP_Services.Services.Controllers
string DatabaseName = _appSettings.ConnectionString; string DatabaseName = _appSettings.ConnectionString;
_appSettings.ConnectionString = _appSettings.AdminConnectionString; _appSettings.ConnectionString = _appSettings.AdminConnectionString;
FTPDataAdapter adapter = new FTPDataAdapter(_appSettings); FTPDataAdapter adapter = new FTPDataAdapter(_appSettings);
List<ConfigValues>? RequestsList = adapter.ConfigValues(CompanyId,DatabaseName); List<ConfigValues>? RequestsList = adapter.ConfigValues(CompanyId, DatabaseName);
return Ok(RequestsList); return Ok(RequestsList);
} }
catch (Exception ex) catch (Exception ex)
...@@ -272,7 +272,7 @@ namespace FTP_Services.Services.Controllers ...@@ -272,7 +272,7 @@ namespace FTP_Services.Services.Controllers
} }
[HttpPost("DownloadBase64DataAsync")] [HttpPost("DownloadBase64DataAsync")]
public async Task<string> DownloadBase64DataAsync(string fileNameWithPath,bool IsExternal) public async Task<string> DownloadBase64DataAsync(string fileNameWithPath, bool IsExternal)
{ {
bool isFTPMODE = _appSettings.FTPConfiguration.FTPMODE; bool isFTPMODE = _appSettings.FTPConfiguration.FTPMODE;
var base64 = string.Empty; var base64 = string.Empty;
...@@ -348,11 +348,11 @@ namespace FTP_Services.Services.Controllers ...@@ -348,11 +348,11 @@ namespace FTP_Services.Services.Controllers
try try
{ {
var fileStream = new FileStream(strFullPath, FileMode.Open, FileAccess.Read,FileShare.Read); var fileStream = new FileStream(strFullPath, FileMode.Open, FileAccess.Read, FileShare.Read);
var base64Stream = new Base64EncodingStream(fileStream); var base64Stream = new Base64EncodingStream(fileStream);
return new FileStreamResult(base64Stream, "application/octet-stream") return new FileStreamResult(base64Stream, "application/octet-stream")
{ {
FileDownloadName = Path.GetFileName(fileNameWithPath) FileDownloadName = Path.GetFileName(fileNameWithPath)
}; };
} }
catch (Exception ex) catch (Exception ex)
...@@ -446,7 +446,7 @@ namespace FTP_Services.Services.Controllers ...@@ -446,7 +446,7 @@ namespace FTP_Services.Services.Controllers
|| response.StatusCode == FtpStatusCode.FileActionOK; || response.StatusCode == FtpStatusCode.FileActionOK;
return success; return success;
} }
//Using for Scan upload //Using for Scan upload
...@@ -1122,16 +1122,38 @@ namespace FTP_Services.Services.Controllers ...@@ -1122,16 +1122,38 @@ namespace FTP_Services.Services.Controllers
} }
[HttpPost("DeleteFTPFile")] [HttpPost("DeleteFTPFile")]
public async Task<int> DeleteFTPFile(string fileNameWithDestinationPath) public async Task<string> DeleteFTPFile(string fileNameWithDestinationPath)
{
bool isFTPMODE = _appSettings.FTPConfiguration.FTPMODE;
string result = string.Empty;
if (isFTPMODE == true)
{
result = await DeleteFileFTPAsync(fileNameWithDestinationPath);
}
else
{
result = await DeleteFileLocallyAsync(fileNameWithDestinationPath);
}
return result;
}
private async Task<string> DeleteFileFTPAsync(string sourceFilePath)
{ {
try try
{ {
string FTPURL = _appSettings.FTPConfiguration.FtpURL.ToString(); string FTPURL = _appSettings.FTPConfiguration.FtpURL.ToString();
string FTPUserName = _appSettings.FTPConfiguration.Username.ToString(); string FTPUserName = _appSettings.FTPConfiguration.Username.ToString();
string FTPPassword = _appSettings.FTPConfiguration.Password.ToString(); string FTPPassword = _appSettings.FTPConfiguration.Password.ToString();
string strSourceFullPath = "";
string strBasePath = _appSettings
.FTPConfiguration.DestinationPathFtp.ToString()
.Trim();
sourceFilePath = sourceFilePath.Replace("/", "\\").TrimStart('\\');
strSourceFullPath = Path.Combine(strBasePath, sourceFilePath);
FtpWebRequest ftp = (FtpWebRequest) FtpWebRequest ftp = (FtpWebRequest)
WebRequest.Create(FTPURL + fileNameWithDestinationPath); WebRequest.Create(FTPURL + strSourceFullPath);
ftp.Credentials = new NetworkCredential(FTPUserName, FTPPassword); ftp.Credentials = new NetworkCredential(FTPUserName, FTPPassword);
ftp.KeepAlive = true; ftp.KeepAlive = true;
ftp.UseBinary = true; ftp.UseBinary = true;
...@@ -1140,21 +1162,36 @@ namespace FTP_Services.Services.Controllers ...@@ -1140,21 +1162,36 @@ namespace FTP_Services.Services.Controllers
FtpWebResponse response = (FtpWebResponse)await ftp.GetResponseAsync(); FtpWebResponse response = (FtpWebResponse)await ftp.GetResponseAsync();
var statuscode = (int)response.StatusCode; var statuscode = (int)response.StatusCode;
response.Close(); response.Close();
return statuscode; return "";
} }
catch (WebException ex) catch (WebException ex)
{ {
FtpWebResponse response = (FtpWebResponse)ex.Response; return "Error deleting file: " + ex.Message.ToString();
if (response.StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable) }
{ }
response.Close();
return 1; private async Task<string> DeleteFileLocallyAsync(string sourceFilePath)
} {
else string strSourceFullPath = "";
try
{
string strBasePath = _appSettings
.FTPConfiguration.DestinationPathFile.ToString()
.Trim();
sourceFilePath = sourceFilePath.Replace("/", "\\").TrimStart('\\');
strSourceFullPath = Path.Combine(strBasePath, sourceFilePath);
if (!System.IO.File.Exists(strSourceFullPath))
{ {
response.Close(); return "Source file does not exist.";
return 0;
} }
System.IO.File.Delete(strSourceFullPath);
return "";
}
catch (Exception ex)
{
return "Error deleting file: " + ex.Message;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment