-
Tuesday, April 14, 2009 6:44 PMda.3vil.genius
da.3vil.genius
65 Points 2 0 0Recent AchievementsForums Answerer I First Marked Answer65 Points
Hello,I'm trying to programmatically upload a file to a
sharepoint list but keep getting the following error:The Web application
at http://mysite.site.com/sites/appdevelop/Project%20Plans/Forms/AllItems.aspx?RootFolder=%2fsites%2fappdevelop%2fProject%20Plans%2fExternal%20Website
could not be found. Verify that you have typed the URL correctly. If the URL
should be serving existing content, the system administrator may need to add a
new request URL mapping to the intended application.Here's the code I'm
using (C#):private void UploadFileToSharePoint(string strInputFileName) { string destUrl = ConfigurationManager.AppSettings["destURL"]; string destFileUrl = destUrl + "/New.txt; SPWeb site = new SPSite(destUrl).OpenWeb(); site.AllowUnsafeUpdates = true; FileStream fileStream = File.Open(strInputFileName, FileMode.Open); site.Files.Add(destFileUrl, fileStream, true/*overwrite*/); fileStream.Close(); }
Can anyone tell me where I'm going wrong?
Thanks in
advance.
Answers
-
Wednesday, April 15, 2009 8:00 AMmanish parab
manish parab
Ag technologies
Partner
85 Points 6 0 0Recent AchievementsForums Replies
I First Marked
Answer Forums Answerer
IAg technologies(Partner)85 Points
I have Modified your
function a little bit..this is how it looksprivate void UploadFileToSharePoint(string strInputFileName,string sDocLibraryName) { string destUrl = ConfigurationManager.AppSettings["destURL"]; SPWeb site = new SPSite(destUrl).OpenWeb(); SPList myList = site.Lists[sDocLibraryName]; string destFileUrl = myList.RootFolder.ServerRelativeUrl + @"/New.txt"; site.AllowUnsafeUpdates = true; FileStream fileStream = File.Open(strInputFileName, FileMode.Open); site.Files.Add(destFileUrl, fileStream, true/*overwrite*/); fileStream.Close(); }
Call To this Function Would Be
UploadFileToSharePoint(@"C:\Ids.txt", "strore 102"/* name of Dc Library*/);
Hope This Helps
regards
Manish
http://mnish.blogspot.com/- Marked As Answer by da.3vil.genius Wednesday, April 15, 2009 3:39 PM
All Replies
-
Tuesday, April 14, 2009 6:52 PMSteve.Curran MVP
Steve.Curran MVP
KnowledgeLake
Partner, MVP
29,435 Points 10 4 2Recent AchievementsProfile
Complete Proposed Answerer
I Forums Replies
IVKnowledgeLake(Partner, MVP)29,435 Points
Try just using http://mysite.site.com/sites/appdevelop/Project%20Plans when
constructing your SPSite object
http://www.certdev.com
-
Tuesday, April 14, 2009 7:28 PMda.3vil.genius
da.3vil.genius
65 Points 2 0 0Recent AchievementsForums Answerer
I First Marked
Answer65 Points
Nope, still the same error.
-
Tuesday, April 14, 2009 7:56 PMSathish TK
Sathish TK
Partner
95 Points 3 0 0Recent AchievementsFirst Answer
Confirmed Forums Answerer
I First Forums
Reply(Partner)95 Points
Are you getting this error in anonymous mode or signed-in?Check the permissions on your list and ensure the proper user group can
add new items to the list.In the code trying using
RunWithElevatedPrivileges of the SPSecurity class (note: this is not the
recommended approach)
http://www.sathishtk.com/blog -
Tuesday, April 14, 2009 8:43 PMMoonis Tahir
Moonis Tahir
MCC, Partner
8,500 Points 12 3 1Recent AchievementsProfile
Complete Forums Answerer
IV Proposed Answerer
I(MCC, Partner)8,500 Points
where you are running your code, on sharepoint box Or on your
development box trying to upload to a different sharepoint server? as long as
you have permissions to the web and your code is running on sharepoint Box,
there should be no issue in creating SPSite object. you can create SPSite object
in RunWithElevatedPrivilage block.
Moonis Tahir MCSD.net, MCTS Sharepoint 07 (Dev & Config), MCTS BizTalk 06,
MCTS SQL 2005. -
Tuesday, April 14, 2009 9:09 PMDave Hunter
Dave Hunter
Portaltech Consulting Li...
Partner, MVP
20,310 Points 11 4 1Recent AchievementsProposed Answerer
I Forums Answerer
IV Forums Replies
IVPortaltech Consulting Li...(Partner, MVP)20,310 Points
You need to use http://mysite.site.com/sites/appdevelop
in your new SPSite(). Project Plans is your document library.The
following should workprivatevoid
UploadFileToSharePoint(string strInputFileName)
{
string
destUrl = http://mysite.site.com/sites/appdevelop;
string destFileUrl =
destUrl + "project%20plans" + "/New.txt;
using(SPWeb site =
new
SPSite(destUrl).OpenWeb())
{
site.AllowUnsafeUpdates = true;FileStream fileStream =
File.Open(strInputFileName, FileMode.Open);
site.Files.Add(destFileUrl, fileStream, true/*overwrite*/);
fileStream.Close();
}
}Hope this helps
Dave
My SharePoint Blog - http://www.davehunter.co.uk/blog -
Wednesday, April 15, 2009 8:00 AM
作者: ancestor
- 该日志由 ancestor 于12年前发表在综合分类下,最后更新于 2012年08月30日.
- 转载请注明: Programmatically Upload a document with new Version to SharePoint List | 学步园 +复制链接
抱歉!评论已关闭.
书签
本站推荐