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.