• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1050
  • Last Modified:

Reading file properties in SQL Server 2005 !!

Hi,

I have a file (ABC.txt) file in C:\Temp folder. I want to read this file properties and place them in a SQL Server database table. Can you please let me know how can i read its properties ?

Appreciate your time and patience !

Thanks
0
kishore_peddi
Asked:
kishore_peddi
  • 2
1 Solution
 
YveauCommented:
When you access another subsystem, you cannot do that by regular SQL code.
So what you might need here (and that is really not a good idea from security standpoint) is use the xp_cmdshell procedure. That way you can run 'DOS' commands and do an 'attrib' or 'dir' of the files.

First enable xp_cmdshell (off by default)

Hope this helps ...

sp_configure 'show advanced options',1
go
reconfigure
go
 
sp_configure 'xp_cmdshell',1
go
reconfigure
go
 
exec xp_cmdshell 'dir C:\'
 
sp_configure 'xp_cmdshell',0
go
reconfigure
go
 
sp_configure 'show advanced options',0
go
reconfigure
go
 
 
--

Open in new window

0
 
nmcdermaidCommented:
You can write a vb.Net console app and link it to a stored proc and do it that way also.
0
 
kishore_peddiAuthor Commented:
Yveau,

Can you just clarify one point please ?

use sample  -- (sample - is my database)
go

sp_configure 'show advanced options',1
go
reconfigure
go
 
sp_configure 'xp_cmdshell',1
go
reconfigure
go
 
exec xp_cmdshell 'dir C:\'  -- (xp_cmdshell => In which database this is residing ? in MASTER or sample)
go            
 
sp_configure 'xp_cmdshell',0
go
reconfigure
go
 
sp_configure 'show advanced options',0
go
reconfigure
go
0
 
YveauCommented:
master
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now