AI/ML, AWS, Azure, DevOps, GCP, M365, Microsoft Power Platform, SharePoint
Wednesday, March 12, 2014
Monday, March 10, 2014
Upload Documents to Document Library using file upload control in SharePoint
In Aspx page:-
------------------
<asp:FileUpload runat="server" ID="FileUpload1"></asp:FileUpload>
<asp:ImageButton runat="server" ID="imgbtnUpdateAttachment" OnClick="fileUpload_Click"
ImageUrl="../SiteAssets/Buttons/update_attachement.png"></asp:ImageButton>
In Aspx.cs Page:-
---------------------
protected void
fileUpload_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile &&
FileUpload1.PostedFile != null)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPSite site = SPContext.Current.Site;
SPWeb web = SPContext.Current.Web;
string DocumentLibName = "Test Temp Documents";
web.AllowUnsafeUpdates = true;
if
(FileUpload1.PostedFile != null)
{
Stream fStream = FileUpload1.PostedFile.InputStream;
byte[] content = new byte[fStream.Length];
fStream.Read(content,
0, (int)fStream.Length);
string Filename = FileUpload1.FileName;
string destUrl = SPContext.Current.Site.Url
+ DocumentLibName + "/" +
Filename;
SPFile spfile = web.Files.Add(destUrl, content, true);
spfile.Item["DocID"] = "1234567";
spfile.Item.Update();
fStream.Flush();
fStream.Close();
fStream.Close();
fStream.Dispose();
}
else
{
throw new FileNotFoundException("File Not Found");
}
web.AllowUnsafeUpdates = false;
});
}
}
-----------------------------------------------------------------
Thank You
Subscribe to:
Posts (Atom)
Featured Post
Build a Secure MCP Server on Azure Functions for Copilot Studio Agents (Entra ID OAuth)
Model Context Protocol (MCP) is quickly becoming the standard way to give AI agents real tools. Copilot Studio can call any remote MCP serve...
Popular posts
-
CAML:- --------- <Where> <IsNotNull> <FieldRef Name='ID' /> </IsNotNull> ...
-
WebForm1.aspx:- ------------------------- <% @ Page Language ="C#" AutoEventWireup ="true" CodeBehind ="...
-
This operation can be performed only on a computer that is joined to a server farm by users who have permissions in SQL Server to read from...
-
Authorize Postman to access SharePoint 1. Register Add-In 2. Grant Permissions to Add-In 3. Generate the Access Token 4. Access th...
-
CreateDocumentSet.aspx <%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %> <%@ Import Namesp...
-
Reading an excel file using HTML 5 and jQuery and save in SharePoint list Reference https://github.com/SheetJS/js-xlsx https://github.co...
-
Read SharePoint list Items using REST API and ReactJS Step1: Create a "ReactDemo" list and list columns as shown below. ...
-
Read excel data from document library saving as list items using CSOM in SharePoint. 1. Upload an excel file into Document library. This ...
-
CAML Query filter between two dates Method 1:- </And><Geq><FieldRef Name='Created' /><Value Type='Date...
