18Apr2016530PMAlpeshPandhidoc
Hi all...
I am not able to form the following logic ... Please help..
In Computer, I have many pdf files . Location - D:\\UploadedFiles
All file-names are unique - I have added Current DateTime as prefix for file Name.
String File = 18Apr2016530PMabcd.pdf
String dateTime = DateTime.UtcNow.Date.ToString("ddMMMyyyy") + DateTime.Now.ToShortTimeString();
String FileName = datetime + File;
----------------
SQL Server –
| ColumnsNames | DataType |
|
| ID | Numeric(18,0) | PK ;Not Null; Auto increment |
| File Name | Varchar(500) | PK, Unique ; Not null |
| Status | bit | 1-Active ; 0-InActive |
| Uploaded By | Numeric(18,0) | Not Null |
| Uploaded Date | Datetime | Not null (Default – Current Date) |
----------------
On GridView,I want the output as follows –
| FileName | UploadedBy | UploadedDate |
|
|
| 18Apr2016530PMabcd.pdf
| Sanjay.Sharma | 1-JAN-2016 | View | Delete |
| 18Apr2016530PMWelfare.pdf
| Mahesh.Bhatt | 5-JAN-2016 | View | Delete |
Logic – I need to get list of files from path D:\\UploadedFiles
I need to check whether all file names are present in database or not.
If not, then I have to delete those records from the database.
Please guide…

Nishant MittalRank #692 · 3.5K reputationPosted Apr 19, 2016, 7:27 PM EDT
Riddhi ValechaRank #794 · 2.9K reputationPosted Apr 19, 2016, 10:22 PM EDT
Nishant MittalRank #692 · 3.5K reputationPosted Apr 19, 2016, 10:26 PM EDT
Riddhi ValechaRank #794 · 2.9K reputationPosted Apr 19, 2016, 10:49 PM EDT
Nishant MittalRank #692 · 3.5K reputationPosted Apr 19, 2016, 10:51 PM EDT
Riddhi ValechaRank #794 · 2.9K reputationPosted Apr 19, 2016, 11:00 PM EDT
Nishant MittalRank #692 · 3.5K reputationPosted Apr 19, 2016, 11:19 PM EDT
Riddhi ValechaRank #794 · 2.9K reputationPosted Apr 20, 2016, 12:12 AM EDT
Nishant MittalRank #692 · 3.5K reputationPosted Apr 20, 2016, 12:16 AM EDT
Rahul ChavanRank #2,671 · 521 reputationPosted Apr 20, 2016, 1:55 AM EDT
Riddhi ValechaRank #794 · 2.9K reputationPosted Apr 21, 2016, 9:20 PM EDT
String[] filenames = Directory.GetFiles(@"D:\");
foreach (string item in filenames)
{
string filename = Path.GetFileName(item);
// Check if filename exists in the sql server column or not.
//if no, then delete file from directory.
}
-----------
The requirement is - I need to check that files present in directory, must be there in SQL Server column.
Eg - Filename - 1jan2016560pmabcdef.pdf - must be present in directory and this name must be there in sql server column.
How to do this ?
There will be thousands of files... so... I need a faster solution....