Quantcast
Channel: SharePoint 2013 - General Discussions and Questions forum
Viewing all articles
Browse latest Browse all 26374

Upload programatically multiple file with same name in doc lib then it shoud not replace the old one. It should create the new entry?

$
0
0

Hi All

Upload programatically multiple file with same name in doc lib then it shoud not replace the old one. It should create the new entry?

Below is my code, If file is existing with same name then its replacing the old one.

But I want to create the new entry with increment ID.

protected

void btnUpload_Click(object sender, EventArgs e)

{

if (fileUpload.HasFile)

{

if (fileUpload.PostedFile.ContentLength > 0)

{

string fileName = fileUpload.FileName;

using (SPWeb oWeb = siteUrl.OpenWeb())

{

oWeb.AllowUnsafeUpdates =

true;

SPDocumentLibrary docLib = oWeb.Lists["ETS-DocFile"] as SPDocumentLibrary;

string fileExtension = fileUpload.FileName.Substring(fileUpload.FileName.IndexOf("."));

byte[] fileByte = fileUpload.FileBytes;

string destUrl = fileName + fileExtension;

SPFile destFile = docLib.RootFolder.Files.Add(destUrl, fileByte, true);

destFile.Update();

oWeb.AllowUnsafeUpdates =

false;

}

}

}


Viewing all articles
Browse latest Browse all 26374

Trending Articles



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