How to add webpartzone in sharepoint 2010 programmatically on C#? - sharepoint-2010

I have a really simple question and probably hard answer.
How to add webpartzone into my sharepoint page using C# code?
What I did is: I create visual web part project and added this code to page_init event of it:
protected void Page_Init(object sender, EventArgs e)
{
WebPartZone webPartZone1 = new WebPartZone();
webPartZone1.AllowLayoutChange = true;
webPartZone1.EmptyZoneText = "No Data are provided";
webPartZone1.Enabled = true;
webPartZone1.HeaderText = "My Custom Zone";
webPartZone1.Visible = true;
this.Page.Controls.Add(webPartZone1);
}
and it's doesn't work. but can give you some idea of what I want. I'm really confused.

I think, what you're trying is a bit wrong, you're trying to add a web part zone in a web part. I don't know if it is possible but you can try to create it via code to a master page.
I mean, you will not add the created web part zone control in "this.page" but to its master.

Related

Visual Studio is not letting me add CefSharpBrowserControl to a form via the designer

So I decided to try out the CefSharp extension, and what's the first thing I encounter? An error that doesn't let me use the add-on.
This is ridiculously frustrating because I've done every single thing even the administrator or creator has said to do on any forum I've been on. I tried to just compile the source code on the CEFSharp's GitHub, but that didn't work.
If I'm brutally honest, I think that they should just provide a pre-compiled .dll file or group of .dll files that you can just add to the references, instead of just expecting you to do it yourself. It's just a pain, CEFSharp.
I've tried putting the Configuration to x64 AND Any CPU. I've tried making references to several different dlls associated to CEFSharp. I've tried to add the browser element programmatically, and that's worked, but I can't do anything with it (such as execute code when the webpage is done loading). So far none of these solutions have worked at all.
Imports CefSharp
Imports CefSharp.WinForms
Public Class Browser
Dim browser As New _
CefSharp.WinForms.ChromiumWebBrowser("https://google.com/")
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles _
MyBase.Load
Me.Controls.Add(browser)
browser.Parent = Panel1
browser.Dock = DockStyle.Fill
End Sub
End Class
Any time I want to add the browser control to my form via the designer toolbox, it won't let me. It keeps showing this error box that says "Failed to load CefSharpBrowser, deleting from the toolbox." Or something along those lines. It's supposed to just be able to drop into the designer, but it's obviously not.
There are similar discussions on CefSharp's google group: Adding CefSharp control to the toolbox and The name "WebView" does not exist in the namespace.
They say that Visual Studio has some limitations when using a mixed mode (C++/CLR) assembly. There is no Visual Studio designer support out of the box in CefSharp. There is some hack about how to do it, but I do not think it worth it to even spend time on it. Most people just accept the fact and move on.
We successfully use CefSharp for one of our projects and we add ChromiumWebBrowser control to a form programmatically, very similar to how you did it in your sample.
I've tried to add the browser element programmatically, and that's
worked, but I can't do anything with it (such as execute code when the
webpage is done loading). So far none of these solutions have worked
at all.
There is a LoadingStateChanged event which you can use to monitor the status of a web browser control. We use it to show progress indication until our web page is fully loaded. Here is how we do it:
private System.Windows.Forms.PictureBox picProgress;
bool loaded = false;
ChromiumWebBrowser browse;
public Main()
{
var uiUrl = "some url or local html file";
browse = new ChromiumWebBrowser(uiUrl);
browse.Dock = DockStyle.Fill;
Controls.Add(browse);
browse.LoadingStateChanged += Browse_LoadingStateChanged;
}
private void Browse_LoadingStateChanged(object sender, LoadingStateChangedEventArgs e)
{
if (!e.IsLoading)
{
picProgress.BeginInvoke((Action)(() => {
loaded = true;
picProgress.Visible = false;
browse.Visible = true;
}));
}
else
{
browse.BeginInvoke((Action)(() => {
loaded = false;
browse.Visible = false;
}));
}
}
Sorry, it is in C#, but I think you can easily adapt it for VB.net.

How to take an xml response received from a web service and make it a datasource

I'm making a windows 8.1 phone app and I have a listbox that I'm trying to populate with data. My problem is that I am using a web service and I finally figured out how to get the data but it is in an xml format and I don't know how to make that into the itemssource for the listbox. I'm sorry if this is a stupid question but this is my first time doing this and I can't seem to find any information online.
Below is a very simple example which requests an XML document from a URI over HTTPS.
It downloads the XML asynchronously as a string and then uses XDocument.Parse() to load it.
private void button2_Click(object sender, RoutedEventArgs e)
{
WebClient wc = new WebClient();
wc.DownloadStringCompleted += HttpsCompleted;
wc.DownloadStringAsync(new Uri("https://domain/path/file.xml"));
}
private void HttpsCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
XDocument xdoc = XDocument.Parse(e.Result, LoadOptions.None);
this.textBox1.Text = xdoc.FirstNode.ToString();
}
}
Have a look over this thread.
Hope it helps!
If the data coming back is always the same type you can always use XmlSerializer to deserialize the data the data to a class you can bind to. If you copy a sample of the data coming back to the clip board you can use paste xml as classes to paste the class you can deserialize into
Deserialize XML in a WP8 Application

How to click back button programatically in IWizardPage in Eclipse

I'm writing an Eclipse plugin, I want to create a wizard for my new project type. I created pages by classes extends org.eclipse.jface.wizard.WizardPage. My requirement is, based on some condition in one page, I need to go back to previous page without pressing back button on page(programmatically).
Is it possible?
Thanks a million in advance!
I don't think this is a good idea. The user will be confused by doing this. I would disable the finish and the next button and give an error, telling the user that he has to go back to the first page.
If you want to reuse some UI from the first page, define the UI as a new class and reuse it.
I implemented something similar using the WizardDialog:showPage() method:
MyWizard.java
public void createPageControls(Composite pageContainer) {
// TODO Auto-generated method stub
super.createPageControls(pageContainer);
wizardDialog = (WizardDialog) getContainer();
}
public void skipProcessPage() {
wizardDialog.showPage(workPage == arisDbPage ? focusPage : arisDbPage);
}
public void setWorkPage(IWizardPage workPage) {
this.workPage = workPage;
}
here the processPage does the lengthy db lookup!
HTH thomas

Trouble Attaching File Programmatically to Email in Windows Metro App C#/XAML using Share Charm

I'm simply trying to attach a file named Document.pdf in the DocumentsLibrary to an email using the Share Charm. My code below works perfectly on the Local Machine:
private async void OnDataRequestedFiles(DataTransferManager sender, DataRequestedEventArgs e)
{
List<IStorageItem> shares = new List<IStorageItem>();
StorageFile filetoShare = await Windows.Storage.KnownFolders.DocumentsLibrary.GetFileAsync("Document.pdf");
if (filetoShare != null)
{
shares.Add(filetoShare);
filetoShare = null;
}
if (shares != null)
{
DataPackage requestData = e.Request.Data;
requestData.Properties.Title = "Title";
requestData.Properties.Description = "Description"; // The description is optional.
requestData.SetStorageItems(shares);
shares = null;
}
else
{
e.Request.FailWithDisplayText("File not Found.");
}
}
But when I run the exact same code on a Windows Surface Tablet, I get the dreaded "There's nothing to share right now." on the right in the Charms flyout area.
Here's a little more background to help:
I'm not looking to use a File Picker...I know the exact file I'm looking for
I've enabled the Documents Library Capability in the manifest
I've added a File Type Association for pdf in the manifest
and yes, the file does exist and is in the Documents Library
an email account is properly setup in the Mail App on the surface
I can successfully send text emails from the Tablet...just not emails with attachments
Like I said, this works on my Win 8 Development Machine as expected...just not on the Surface. I'm wondering if the Surface has different file or folder permissions?
Thanks for the help...this is driving me CRAZY
I finally figured it out - the problem was that my Event Handler was async (so that I could use await to set the StorageFile variable).
I solved it by setting the StorageFile variable earlier in my code so that it was already available when the Event Handler was called.
I still have no idea why it worked on my development machine, but no on the WinRT surface...
The handler can be an async method. In this case, it is critical to use DataTransferManager. Please refer to the MSDN page specifically for this scenario. For your convenience, the code from the page is copied to here:
private void RegisterForShare()
{
DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager,
DataRequestedEventArgs>(this.ShareStorageItemsHandler);
}
private async void ShareStorageItemsHandler(DataTransferManager sender,
DataRequestedEventArgs e)
{
DataRequest request = e.Request;
request.Data.Properties.Title = "Share StorageItems Example";
request.Data.Properties.Description = "Demonstrates how to share files.";
// Because we are making async calls in the DataRequested event handler,
// we need to get the deferral first.
DataRequestDeferral deferral = request.GetDeferral();
// Make sure we always call Complete on the deferral.
try
{
StorageFile logoFile =
await Package.Current.InstalledLocation.GetFileAsync("Assets\\Logo.png");
List<IStorageItem> storageItems = new List<IStorageItem>();
storageItems.Add(logoFile);
request.Data.SetStorageItems(storageItems);
}
finally
{
deferral.Complete();
}
}
It is critical to place the following statement before any async method is called:
DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
You only have half a second to get the whole job done (getting the file, attaching...etc.). If the half-second deadline occurs you'll get this "driving crazy" message. Consider implementing some resumable logic and replace the message with "the attachment is being prepared please try again in a few seconds" (or else).
Your WinRT device might be just slower than your development machine. The latter just does the job before the deadline...

Problem saving a new item to custom SharePoint 2007 list using Silverlight 4 UI control

I am hoping someone might be able to help me. I'm working on a Contact Manager built using a custom SharePoint 2007 list with a Silverlight 4 UI embedded in a content editor web part.
I am currently able to retrieve the data from the list and display it in a datagrid on the UI and everything works well.
Now I am trying to add the the ability to add new items to the list using the following code but the items do not save.
I've remotely debugged the following code using the Debug -> Attach to Process option and everything seems to execute successful without any errors but it does not save the item to SharePoint.
In order to simplify and get a working insert function I changed all the SharePoint fieds to single line text with the exception of the notes (multiline) and none of the fileds are required.
The sharepoint site does require Windows authentication but it seems to be working correctly as I am able to display it as well as add new items manually using the standard SharePoint forms.
Lastly, I have added the xml for the Batch element at the bottom which I copied as output while debuging.
Please let me know if there is any additional information I might be missing.
Thanks in advance for any assistance you might be willing to provide.
Charles
public string sharepoint_soap_namespace = "http://schemas.microsoft.com/sharepoint/soap/";
public string sharepoint_rowset_namespace = "#RowsetSchema";
public string service_lists_url = "http://myDomain/_vti_bin/lists.asmx";
public string listName = "MyContacts";
public void TestCreateContact()
{
Uri serviceUri = new Uri(service_lists_url);
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
binding.MaxReceivedMessageSize = 2147483647; // This has to be the same as in the ServiceReferences.ClientConfig file.
EndpointAddress endpoint = new EndpointAddress(serviceUri);
ListsSoapClient testCreateClient = new ListsSoapClient(binding, endpoint);
XElement batch = new XElement("batch",
new XElement("Method",
new XAttribute("ID", "1"),
new XAttribute("Cmd", "New"),
CreateFieldElement("ows_ID", "New"),
CreateFieldElement("ows_Title", "John"),
CreateFieldElement("ows_SupportFor","USA"),
CreateFieldElement("ows_LastName","Doe")
));
testCreateClient.UpdateListItemsCompleted +=
new EventHandler<UpdateListItemsCompletedEventArgs>(createSoapClient_UpdateListItemsCompletedEventArgs);
testCreateClient.UpdateListItemsAsync(listName, batch);
testCreateClient.CloseAsync();
}
private XElement CreateFieldElement(string fieldName, string fieldValue)
{
XElement element = new XElement("Field",
new XAttribute("Name", fieldName),
fieldValue);
return element;
}
Just a quick update to let everyone know I was able to answer my own question.
It seems that in the batch XElement I was using the wrong field names.
CreateFieldElement("ows_SupportFor","USA"),
I was using "ows_SupportFor" instead of "SupportFor" without the "ows_" prefix.
Cheers,
Charles