You are on page 1of 3

6/20/13

vb.net - About Uploading multiple files and giving the filename to fileupload control programatically in asp.net - Stack Overflow

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Tell me more

About Uploading multiple files and giving the filename to fileupload control programatically in asp.net

My client has one requirement. He wants to upload all the text files from folder "D:/MyFolder/" by clicking on a button. So I tried It but I am having the problems. Here is the code:

P r o t e c t e dS u bb t n A u t o U p l o a d _ C l i c k ( B y V a ls e n d e rA sO b j e c t ,B y V a leA sS y s t e m . E v e n t A r g s )H a n d l e sb t n A u t o U p l o a d . C l i c k D i md b P r o v i d e rA sS t r i n g D i md b S o u r c eA sS t r i n g D i mc o nA sN e wO l e D b C o n n e c t i o n D i mS Q LA sS t r i n g D i md aA sO l e D b D a t a A d a p t e r D i md sA sN e wD a t a S e t ' C o n n e c t i n ga n dr e t r i e v i n gd a t af o r mD a t a b a s e . d b P r o v i d e r=" P R O V I D E R=M i c r o s o f t . A c e . O L E D B . 1 2 . 0 ; " d b S o u r c e=" D a t aS o u r c e=' "&S e r v e r . M a p P a t h ( " ~ / A p p _ D a t a / D a t a . a c c d b " )&" ' " c o n . C o n n e c t i o n S t r i n g=d b P r o v i d e r&d b S o u r c e S Q L=" S E L E C T*F R O Mt b l U s e r D e t a i l sW H E R EU s e r T y p e=' C o m p a n y ' " d a=N e wO l e D b D a t a A d a p t e r ( S Q L ,c o n ) d s . C l e a r ( ) d a . F i l l ( d s ," t b l U s e r D e t a i l s " ) D i mf i l e U p l o a d P a t hA sS t r i n g=" C : / M U N I M / " D i mN u m b e r O f F i l e s T o U p l o a dA sI n t e g e r=F i l e C o u n t ( f i l e U p l o a d P a t h )

stackoverflow.com/questions/16503823/about-uploading-multiple-files-and-giving-the-filename-to-fileupload-control-pro

1/3

6/20/13

vb.net - About Uploading multiple files and giving the filename to fileupload control programatically in asp.net - Stack Overflow
D i mE x t e n s i o nA sS t r i n g D i mf i l e N a m eA sS t r i n g D i mf i l e s ( )A sS t r i n g f i l e s=I O . D i r e c t o r y . G e t F i l e s ( f i l e U p l o a d P a t h ) F o rxA sI n t e g e r=0T oN u m b e r O f F i l e s T o U p l o a d-1 E x t e n s i o n=I O . P a t h . G e t E x t e n s i o n ( f i l e s ( x ) ) How is this possible? I fE x t e n s i o n=" . t x t "T h e n Should I use FileUpload Control? f i l e N a m e=I O . P a t h . G e t F i l e N a m e W i t h o u t E x t e n s i o n ( f i l e s ( x ) ) If yes, then How can I select specific folder to upload files from? I ff i l e N a m e=d s . T a b l e s ( " t b l U s e r D e t a i l s " ) . R o w s ( x ) . I t e m ( " F i l e N a m e " )T h e n Or How should I give Filename to FileUpload Control Programatically? as it is readonly.
asp.net vb.net file-upload

' C o u n tt h en o .o fd o c u m e n tu p l o a d e r s D i ml i n e C o u n t=I O . F i l e . R e a d A l l L i n e s ( d o c u m e n t V i e w e r s P a t h ) . L e n g t h

D i ma l l L i n e sA sN e wL i s t ( O fS t r i n g ) D oW h i l eN o tr e a d e r . E n d O f S t r e a m a l l L i n e s . A d d ( r e a d e r . R e a d L i n e ( ) ) Answer L o o p r e a d e r . C l o s e ( ) You cant really have your server just grab files off a clients machine legitimately. This is what the file upload control is for. Generally the client initiates the upload. F o riA s I n t e g e r =0T o l i n e C o u n t-1 I fd s . T a b l e s ( " t b l U s e r D e t a i l s " ) . R o w s ( x ) . I t e m ( " U s e r N a m e " )=R e a d L i n e ( i ,a l l L i n e s )T h e n You can use file upload control with multiple attribute to allow you to select multiple files in IE version 10+ , FF, Chrome, Opera. Otherwise, without the multiple attribute it is tedious to upload files since you can't ' S a v et h ef i l et od e s i r e dl o c a t i o n( U p l o a dF i l e ) shift / control click all files. You will save the file's in the E n httpfilecollection dI f and simply loop through and use the .SaveAs property to save to your destination file. I can provide same code if you need.. N e x t A s p E n dI f < a s p : F i l e U p l o a dI D = " F i l e U p l o a d 1 "m u l t i p l er u n a t = " s e r v e r "/ > E n dI f < b r/ > N e x t < a s p : B u t t o nI D = " B u t t o n 1 "r u n a t = " s e r v e r "T e x t = " U p l o a d "o n c l i c k = " B u t t o n 1 _ C l i c k " E n d S u b H e i g h t = " 2 6 p x "/ > c# You or someone please convert, I have not done vb in ages :P p r o t e c t e dv o i dB u t t o n 1 _ C l i c k ( o b j e c ts e n d e r ,E v e n t A r g se ) { H t t p F i l e C o l l e c t i o nh f c=R e q u e s t . F i l e s ; f o r( i n ti=0 ;i! =h f c . C o u n t ;i + +) { h f c [ i ] . S a v e A s ( @ " D : \ M y F o l d e r \ "+h f c [ i ] . F i l e N a m e ) ; } } In production , this would require your server to have folder rights.
edited May 12 at 4:20 answered May 12 at 4:14 Chris Buckler 987 1 4 20

asked May 12 at 3:09 ' r e a d i n gt h en a m e so fd o c u m e n tu p l o a d e r s Vishal D i mr e a d e rA sN e wS y s t e m . I O . S t r e a m R e a d e r ( d o c u m e n t V i e w e r s P a t h ) 231 1 9

I have tried to use your code as you suggested but I am not able to select multiple files. In fact first I got the warning that multiple should be followed by = sign. So I changed it to multiple = "true". But still I am not able to select multiple files. Vishal May 12 at 14:34 What browser are you using? Chris Buckler May 12 at 20:30 I am using IE 10 Vishal May 12 at 21:15 Not sure what to tell you good sir, I just re copied back in the code and I can shift + multiple files into the upload control. Chris Buckler May 13 at 14:35

Not the answer you're looking for? Browse other questions tagged asp.net vb.net
file-upload or ask your own question.
stackoverflow.com/questions/16503823/about-uploading-multiple-files-and-giving-the-filename-to-fileupload-control-pro 2/3

6/20/13

vb.net - About Uploading multiple files and giving the filename to fileupload control programatically in asp.net - Stack Overflow

stackoverflow.com/questions/16503823/about-uploading-multiple-files-and-giving-the-filename-to-fileupload-control-pro

3/3

You might also like