HilFiger
Guest
|
Posted:
Mon Oct 24, 2005 4:51 pm Post subject:
MY WebPart Can't Upload file |
|
|
My Code Cann't Running:
My WebPart Is To Upload File...
Could You Help Me?? Where Is Wrong that WebPart Cann't Upload File
using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebPartPages;
using System.Web.UI.HtmlControls;
using Microsoft.SharePoint.WebControls;
namespace vanGeneFlashUpload
{
/// <summary>
/// Description for FlashUpload.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:FlashUpload runat=server></{0}:FlashUpload>"),
XmlRoot(Namespace="vanGeneFlashUpload")]
public class FlashUpload : Microsoft.SharePoint.WebPartPages.WebPart
{
HtmlInputFile NewDoc;
HtmlButton btnBeginUpload;
Label _label;
// private const string defaultText = "";
//
// private string text = defaultText;
//
// [Browsable(true),
// Category("Miscellaneous"),
// DefaultValue(defaultText),
// WebPartStorage(Storage.Personal),
// FriendlyName("Text"),
// Description("Text Property")]
// public string Text
// {
// get
// {
// return text;
// }
//
// set
// {
// text = value;
// }
// }
/// <summary>
/// This method gets the custom tool parts for this Web Part by overriding
the
/// GetToolParts method of the WebPart base class. You must implement
/// custom tool parts in a separate class that derives from
/// Microsoft.SharePoint.WebPartPages.ToolPart.
/// </summary>
///<returns>An array of references to ToolPart objects.</returns>
// public override ToolPart[] GetToolParts()
// {
// ToolPart[] toolparts = new ToolPart[2];
// WebPartToolPart wptp = new WebPartToolPart();
// CustomPropertyToolPart custom = new CustomPropertyToolPart();
// toolparts[0] = wptp;
// toolparts[1] = custom;
// return toolparts;
// }
/// <summary>
/// Render this Web Part to the output parameter specified.
/// </summary>
/// <param name="output"> The HTML writer to write out to </param>
///
protected override void CreateChildControls()
{
NewDoc = new HtmlInputFile();
this.Controls.Add(NewDoc);
_label = new Label();
this.Controls.Add(_label);
btnBeginUpload = new HtmlButton();
btnBeginUpload.InnerText = "Upload";
btnBeginUpload.ServerClick += new EventHandler(btnBeginUpload_Upload);
// _label.Text = "Label Test";
this.Controls.Add(btnBeginUpload);
}
private void btnBeginUpload_Upload(object sender, EventArgs e)
{
string fileName = System.IO.Path.GetFileName(NewDoc.PostedFile.FileName);
// byte[] content = new byte[NewDoc.PostedFile.InputStream.Length];
//
// NewDoc.PostedFile.InputStream.Read(content, 0,
(int)NewDoc.PostedFile.InputStream.Length);
//
// SPWeb web = SPControl.GetContextWeb(this.Context);
// web.AllowUnsafeUpdates = true;
//
// SPFolder docs = web.Folders["Shared documents"];
// SPFile newFile = docs.Files.Add(fileName, content);
// web.AllowUnsafeUpdates = false;
NewDoc.PostedFile.SaveAs("C:\\" + fileName);
}
protected override void RenderWebPart(HtmlTextWriter output)
{
// output.Write(SPEncode.HtmlEncode(Text));
// btnBeginUpload.RenderControl(output);
// NewDoc.RenderControl(output);
//
// _label.RenderControl(output);
RenderChildren(output);
}
}
} |
|