作業ソリューション。みんなありがとう。お役に立てれば。これには、sharepoint の絶対 URL を取得してデータベース列に格納し、画像を sharepoint pic ライブラリに格納することが含まれます。
ありがとうニコラス
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.ComponentModel;
using Microsoft.SharePoint;
namespace UploadDataImage.UploadImage
{
public partial class UploadImageUserControl : UserControl
{
string absURL = string.Empty;
SqlConnection con = new SqlConnection("server = SP-DEV-MACHINE; Initial Catalog=The_Performance; Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
con.Open();
SqlCommand command = new SqlCommand("select Project_ID from Test1", con);
command.ExecuteNonQuery();
DropDownList1.DataSource = command.ExecuteReader();
DropDownList1.DataValueField = "Project_ID";
DropDownList1.DataBind();
con.Close();
}
protected void Btnupload_Click(object sender, EventArgs e)
{
con.Open();
using (SPSite site = new Microsoft.SharePoint.SPSite(SPContext.Current.Site.Url))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
Stream StreamImage = null;
if (FileUpload1.HasFile)
{
StreamImage = FileUpload1.PostedFile.InputStream;
SPList pics = web.Lists["picture"];
SPListItem li = pics.RootFolder.Files.Add(FileUpload1.FileName, StreamImage).GetListItem();
absURL = li.Web.Url +"/"+ li.Url;
SqlCommand cmd = new SqlCommand("insert into Newsss values ('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "','" + TextBox6.Text + "','" + TextBox7.Text + "','" + TextBox8.Text + "','" + TextBox9.Text + "','" + TextBox10.Text + "','" + absURL + "' )", con);
cmd.ExecuteNonQuery();
con.Close();
Label7.Visible = true;
Label7.Text = "success";
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
TextBox6.Text = "";
TextBox7.Text = "";
TextBox8.Text = "";
TextBox9.Text = "";
TextBox10.Text = "";
}
}
}
}
}
}