Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Uploading file to document library getting issue

$
0
0

Hi,

I using SharePoint 2010,

I use below code for to upload file to my SharePoint document library.                   

try {                
                if (fileUpload1.HasFile)
                {                   
                    web.AllowUnsafeUpdates = true;                    
                    SPList docLibrary = web.Lists["Documents2"];                   
                    string a = System.IO.Path.GetExtension(fileUpload1.FileName).ToLower();
                    if (a == ".doc" || a == ".docx" || a == ".pdf")
                    {                       
                        if (Convert.ToDouble(fileUpload1.PostedFile.ContentLength) <= 15728640)
                        {                           
                            Stream fStream = fileUpload1.PostedFile.InputStream;      
                            SPFile file = web.Files.Add("http://testsite" + "/" + docLibrary + "/" + fileUpload1.FileName, fStream, true);
                           file.Update();
                            docLibrary.Update();
                            web.AllowUnsafeUpdates = false;
                        }

 }
            catch (Exception ex)
            {
                Logger.ExceptionLog(ex.Message.ToString());
            }

But it throws the exception as "Value does not fall within the expected range".

Can anyone help on this issue. thanks in advance.


Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>